Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme

Do not, under any circumstances, edit core WordPress files.

The bug is not in WordPress. If it were the proper way to handle such a bug is not to edit WordPress. The right way is to downgrade PHP to a compatible version that doesn’t cause the error and file a bug report at https://core.trac.wordpress.org, if you’re comfortable doing so.

So why does the error message say the problem is in class-wp-hook.php?

In WordPress theme and plugin developers add their own functionality using hooks. This involves telling WordPress to run a given callback when the hook is called. The code that executes these hooked callbacks exists in class-wp-hook.php, so if there is a problem with the callback then error messages will often blame class-wp-hook.php.

Despite this, I can say with a high degree of confidence that significant bugs in class-wp-hook.php are incredibly unlikely to make it into a release version of WordPress, as its entire API is built around hooks and such bugs would be caught almost immediately. Therefore error messages in class-wp-hook.php are almost certainly the fault of a theme or plugin. If something like xdebug is available then you might be able to get more detailed errors that provide more clues, but often the name of class or function in the error message will reveal the true culprit.


So what’s the problem in your situation?

As I mentioned, developers provide callbacks for WordPress to call. If the callback provided is in this format:

array( 'WPCom_Theme_Updater', 'maybe_nag_for_plugin' )

Then when WordPress executes the callback PHP will call:

WPCom_Theme_Updater:: maybe_nag_for_plugin();

This is PHP for calling maybe_nag_for_plugin() as a static method of the WPCom_Theme_Updater class. The problem is that maybe_nag_for_plugin() has not been explicitly declared as a static method by the theme author, and as of PHP 8.0.0 this will throw an error.

So your theme’s author needs to add a static declaration to the maybe_nag_for_plugin() method of the WPCom_Theme_Updater class. Since this is not your own code the theme author will need to make the change or it will be reverted the next time the theme is updated.

As with WordPress, the proper way to handle a compatibility issue in a theme or plugin is to revert to a compatible PHP version and report the issue to the developer. You should always try to avoid modifying code for which you do not control future updates.

One thing to keep in mind is that this error means that your theme has not been tested with PHP 8, so fixing this one issue may just reveal other similar issues that need to be resolved. This is another good reason to revert to a compatible version and seek the author’s assistance.