WordPress 6.0 class-wp-widget.php fatal errors in PHP 8.1.6

I suspect the cause is a custom widget that has been built incorrectly. Take a look at this example from the Codex:

class My_Widget extends WP_Widget {

    /**
     * Sets up the widgets name etc
     */
    public function __construct() {
        $widget_ops = array( 
            'classname' => 'my_widget',
            'description' => 'My Widget is awesome',
        );
        parent::__construct( 'my_widget', 'My Widget', $widget_ops );
    }

What a lot of poorly built plugins do is this:

class My_Widget extends WP_Widget {

    /**
     * Sets up the widgets name etc
     */
    public function __construct() {
        parent::__construct();
    }

Or they fail to include a __construct method at all! Passing no parameters or not having a constructor is incorrect. Past versions of PHP may have substituted these values for null or undefined, resolving to ”`, but I would still have expected this to become a problem before upgrading to 8.1, and it would certainly have appeared in the error log as a notice.

So identify which plugin or theme is responsible for this, either with stack traces, or a process of elimination, perhaps even by doing a search of the codebase with a tool.

If this is in code that you maintain such as a custom theme or plugin, you can resolve the issue by implementing the Widget API correctly as the Codex and the devhub handbooks instruct. Specifically, by providing the first two parameters.

If you’re not interested in fixing the widgets, you can also remove them from your site completely.


In the meantime, downgrade to 8.0 for a little while. Both 8.0 and 8.1 are currently supported versions of PHP and receiving updates. WordPress has yet to build official support for 8.0, and 8.1 is a very recent release ( early 2022 ), so it’s unsurprising you encountered compatibility issues and clashes with 3rd party code when you upgraded.