admin管理员组文章数量:1126988
Recently updated to PHP8 and I'm getting a critical error related to the theme.
The critical error is:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /www/scottsimonbooks_396/public/wp-includes/class-wp-widget-factory.php on line 62 and at least 2 expected in /www/scottsimonbooks_396/public/wp-includes/class-wp-widget.php:163 Stack trace: #0 /www/scottsimonbooks_396/public/wp-includes/class-wp-widget-factory.php(62): WP_Widget->__construct() #1 /www/scottsimonbooks_396/public/wp-includes/widgets.php(115): WP_Widget_Factory->register('thinker_recentp...') #2 /www/scottsimonbooks_396/public/wp-content/themes/thinker/inc/widgets.php(78): register_widget('thinker_recentp...') #3 /www/scottsimonbooks_396/public/wp-content/themes/thinker/functions.php(241): require('/www/scottsimon...') #4 /www/scottsimonbooks_396/public/wp-settings.php(585): include('/www/scottsimon...') #5 /www/scottsimonbooks_396/public/wp-config.php(87): require_once('/www/scottsimon...') #6 /www/scottsimonbooks_396/public/wp-load.php(50): require_once('/www/scottsimon...') #7 /www/scottsimonbooks_396/public/wp-blog-header.php(13): require_once('/www/scottsimon...') #8 /www/scottsimonbooks_396/public/index.php(17): require('/www/scottsimon...') #9 {main} thrown in /www/scottsimonbooks_396/public/wp-includes/class-wp-widget.php on line 163
I tried updating class-wp-widget-factory.php on line 63 by swapping:
$this->widgets[ $widget ] = new $widget();
for this $this->widgets[ $widget ] = new $widget( $widget, $widget );
but with no effect.
('thinker_recentp...') is a recent posts widget.
The code at line 163 in wp-includes/class-wp-widget.php is:
if ( ! empty( $id_base ) ) {
$id_base = strtolower( $id_base );
} else {
$id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) );
}
$this->id_base = $id_base;
$this->name = $name;
$this->option_name = 'widget_' . $this->id_base;
$this->widget_options = wp_parse_args(
$widget_options,
array(
'classname' => str_replace( '\\', '_', $this->option_name ),
'customize_selective_refresh' => false,
)
);
$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
}```
Recently updated to PHP8 and I'm getting a critical error related to the theme.
The critical error is:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /www/scottsimonbooks_396/public/wp-includes/class-wp-widget-factory.php on line 62 and at least 2 expected in /www/scottsimonbooks_396/public/wp-includes/class-wp-widget.php:163 Stack trace: #0 /www/scottsimonbooks_396/public/wp-includes/class-wp-widget-factory.php(62): WP_Widget->__construct() #1 /www/scottsimonbooks_396/public/wp-includes/widgets.php(115): WP_Widget_Factory->register('thinker_recentp...') #2 /www/scottsimonbooks_396/public/wp-content/themes/thinker/inc/widgets.php(78): register_widget('thinker_recentp...') #3 /www/scottsimonbooks_396/public/wp-content/themes/thinker/functions.php(241): require('/www/scottsimon...') #4 /www/scottsimonbooks_396/public/wp-settings.php(585): include('/www/scottsimon...') #5 /www/scottsimonbooks_396/public/wp-config.php(87): require_once('/www/scottsimon...') #6 /www/scottsimonbooks_396/public/wp-load.php(50): require_once('/www/scottsimon...') #7 /www/scottsimonbooks_396/public/wp-blog-header.php(13): require_once('/www/scottsimon...') #8 /www/scottsimonbooks_396/public/index.php(17): require('/www/scottsimon...') #9 {main} thrown in /www/scottsimonbooks_396/public/wp-includes/class-wp-widget.php on line 163
I tried updating class-wp-widget-factory.php on line 63 by swapping:
$this->widgets[ $widget ] = new $widget();
for this $this->widgets[ $widget ] = new $widget( $widget, $widget );
but with no effect.
('thinker_recentp...') is a recent posts widget.
The code at line 163 in wp-includes/class-wp-widget.php is:
if ( ! empty( $id_base ) ) {
$id_base = strtolower( $id_base );
} else {
$id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) );
}
$this->id_base = $id_base;
$this->name = $name;
$this->option_name = 'widget_' . $this->id_base;
$this->widget_options = wp_parse_args(
$widget_options,
array(
'classname' => str_replace( '\\', '_', $this->option_name ),
'customize_selective_refresh' => false,
)
);
$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
}```
Share
Improve this question
edited Feb 24, 2023 at 10:29
Gavin
asked Feb 24, 2023 at 10:01
GavinGavin
11 silver badge2 bronze badges
3
|
1 Answer
Reset to default 1The error indicates that the WP_Widget::__construct() function expects at least two arguments to be passed but none were passed in the line of code where the error occurred. This could due to the upgrade to PHP 8 which is stricter about argument counts.
To fix the issue, you need to modify the code in the "recent posts" widget class in ( wp-content/themes/thinker/inc/widgets.php) to include the required arguments in the constructor function for the WP_Widget class. You need to modify the line that creates a new instance of the WP_Widget class like this:
Replace this code:
parent::__construct( 'thinker_recentposts', __( 'Thinker Recent Posts', 'thinker' ), $widget_ops );
with this code:
parent::__construct( 'thinker_recentposts', __( 'Thinker Recent Posts', 'thinker' ), array( 'description' => __( 'Displays recent posts with thumbnails', 'thinker' ) ) );
The difference is that we have added an array containing the "description" parameter, which is one of the required arguments for the WP_Widget constructor.
Once you have made this change, save the file and try reloading. The error message should no longer appear..
本文标签: theme developmentWordPress PHP8 Critical Error in classwpwidgetphp
版权声明:本文标题:theme development - WordPress PHP8 Critical Error in class-wp-widget.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736688348a1947782.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'thinker_recentp...'
, Do you know what that could be? – Jacob Peattie Commented Feb 24, 2023 at 10:11