WordPress PHP8 Critical Error in class-wp-widget.php

The 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..