Bug in custom HTML widget

Posted in: Newspaper
Post count: 6

Hi,

I found a bug in custom HTML widget when using WPML. Fatal error happens if you place a custom HTML widget choosing some language to display and visitor is browsing in a different language.

Stpes to reproduce
——————

  1. Add a custom HTML widget
  2. Select “Display in language” — spanish, for example.
  3. Browse a page where sidebar is shown getting it in english, for example.

You’ll get a fatal error:

Uncaught TypeError: array_merge(): Argument #2 must be of type array, bool given in /wp-includes/widgets/class-wp-widget-custom-html.php:133

Problematic code line is #2939 located in td_wp_booster_functions.php:

call_user_func_array(array($currentWidgetInstance, 'widget'), array($widgetArgs, $currentWidgetInstanceSettings));

This call passes false as second parameter and called function expetcs an array. PHP 7 passes this error but PHP 8 throws a fatal error.

Site settings
————-

  • Theme version: 12.6.5
  • PHP version: 8.3.3
  • WP version: 6.5.2

Regards

Post count: 27744

Hello,

Please try to use PHP version 8.0 and check if the issue persists. This element is from WordPress, not from the theme.

Thank you!

Post count: 6

Hi,

Yes, this widget is a WP native element, but displayed content is filtered by a hook by TagDiv. This is the code at line #2919 in wp-content/plugins/td-composer/legacy/common/wp_booster/td_wp_booster_functions.php:

/**
* Filter sets the global block template to the wp widgets
* @see 'widget_display_callback' hook on 'class-wp-widget.php'
*/
add_filter('widget_display_callback', 'on_widget_display_callback', 10, 3);
function on_widget_display_callback($currentWidgetInstanceSettings, $currentWidgetInstance, $widgetArgs) {

if( isset($widgetArgs['widget_id']) && strpos($widgetArgs['widget_id'], 'td_block') !== 0 ) {
// var_dump($widgetArgs);
// var_dump($currentWidgetInstance);
$global_block_template_id = td_options::get('tds_global_block_template', 'td_block_template_1');
$widgetArgs['before_widget'] = str_replace(' class="', " class=\"$global_block_template_id ", $widgetArgs['before_widget']);

$block_title_class = 'td-block-title';
if ($global_block_template_id === 'td_block_template_1') {
$block_title_class = 'block-title';
}
$widgetArgs['before_title'] = '<h4 class="' . $block_title_class . '"><span>';
$widgetArgs['after_title'] = '</span></h4>';

call_user_func_array(array($currentWidgetInstance, 'widget'), array($widgetArgs, $currentWidgetInstanceSettings));

// Returning false will effectively short-circuit display of the widget.
return false;
}

// Returning $currentWidgetInstanceSettings, as the apply_filters of this hook require
return $currentWidgetInstanceSettings;
}

If you comment “add_filter” line all works fine. The problem is that the instruction

call_user_func_array(array($currentWidgetInstance, 'widget'), array($widgetArgs, $currentWidgetInstanceSettings));

sends false as second parameter but called function expects an array.

Anyway I tried PHP 8.0 as you suggested but error persists. If you want to check it out I can send you URL and credentials.

Regards.

Post count: 27744

Hi,

We can take a look. Please get in touch with us via email at contact@tagdiv.com and provide the following wp-admin and cPanel URL and credentials.

Thank you!

Post count: 6

Hi,

The proposed solution you gave me by email (using WPML String Translation) works for me at the moment but in my opinion it’s a workaround for a problem that should be fixed.

Thank you very much for your interest.

Regards.

Post count: 27744

Hi,

This is how it works.

Thank you!

Post count: 3

Hi, this issue can be fixed by checking the value of the $currentWidgetInstanceSettings argument (which could be empty) in the on_widget_display_callback(); e.g. replacing the line 2929:

if( isset($widgetArgs['widget_id']) && strpos($widgetArgs['widget_id'], 'td_block') !== 0 ) {

with

if( $currentWidgetInstanceSettings && isset($widgetArgs['widget_id']) && strpos($widgetArgs['widget_id'], 'td_block') !== 0 ) {

Post count: 3

if( $currentWidgetInstanceSettings !== false && isset($widgetArgs['widget_id']) && strpos($widgetArgs['widget_id'], 'td_block') !== 0 ) {
is better; PLEASE add this fix to next releases.

Post count: 3

Hi, why has it not been fixed yet??? Everytime I update the Newspaper theme and the plugins I find this issue again. Please, fix it!.
My website has some widgets which are shown or hidden using WPML, depending on the language of the current page, but there could be any other plugin out there that hides a widget based on any condition and returns false, so this issue MUST be fixed, also considering that the PHP versions before the 8 are not supported anymore.

Post count: 35449

Hi,
This is on our list to be checked. I just made a push for it so our developers can check it as soon as possible.

Viewing 10 posts - 1 through 10 (of 10 total)
The forum ‘Newspaper’ is closed to new topics and replies.