PHP warning about passing string, expected array
-
After updating to Live Chat 8.1.1 a PHP warning is displayed on front end pages from the plugin functions.php file, line 1851, indicating parameter 2 of the in_array function is expecting an array, but received a string. This happens in performing a check of the wplc_exclude_post_types setting. Trying to change ‘Exclude chat window on selected post types’ under General Settings produces a fatal error.
The following code fixes the warning on the front end:
function pws_fix_wplc_settings () { $wplc_settings = get_option('WPLC_SETTINGS'); if ( isset($wplc_settings['wplc_exclude_post_types']) && ! is_array($wplc_settings['wplc_exclude_post_types']) ) { $wplc_settings['wplc_exclude_post_types'] = array(); update_option('WPLC_SETTINGS', $wplc_settings); } } add_action('init', 'pws_fix_wplc_settings', 10, 0);
However, the default setting is an empty string which still causes a fatal error when saving the settings: Fatal error: Uncaught Error: [] operator not supported for strings in wp-live-chat-support.php on line 3640. The default setting should probably be changed to an empty array.
- The topic ‘PHP warning about passing string, expected array’ is closed to new replies.