Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
-
I have two WordPress sites with theme Dyad 2 https://wordpress.com/theme/dyad-2
I need to upgrade from PHP 7.4 to 8.1, but when I try I got four “Deprecated: Non-static” errors. I managed to fix all but this one:
Deprecated: Non-static method WPCom_Theme_Updater::maybe_nag_for_plugin() should not be called statically in public_html/wp-includes/class-wp-hook.php on line 307. Line 307 is “$value = call_user_func_array( $the_[‘function’], $args );“, and in some context here:... ... // Avoid the array_slice() if possible. if ( 0 == $the_['accepted_args'] ) { $value = call_user_func( $the_['function'] ); } elseif ( $the_['accepted_args'] >= $num_args ) { $value = call_user_func_array( $the_['function'], $args ); } else { $value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int) $the_['accepted_args'] ) ); ... ...The whole code is here (.OLD is the original). Right now I think they are both identical as whatever I tried, I got worse errors and not functioning site. And editing WordPress core files is not really a good thing to do ;)
class-wp-hook.php: https://justpaste.it/72r0g
class-wp-hook.php.OLD: https://justpaste.it/2tmrnI’m guessing that it has something to do with the file public_html/wp-content/themes/dyad-2-wpcom/inc/updater.php because it has WPCom_Theme_Updater and maybe_nag_for_plugin() And it was also one of the files that gave most of the “Deprecated: Non-static” errors, so I had to change a lot of “self::” to “(new self)->”
The whole code is here (.OLD is the original).
updater.php: https://justpaste.it/4tgpf
updater.php.OLD: https://justpaste.it/8kkqcAcording to the anwser I got here:
https://wordpress.stackexchange.com/questions/408742/need-help-with-deprecated-non-static-error-when-update-php-7-4-8-1-with-dyad/408745#408745So 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.
Is it here I can ask the theme’s author to add a static declaration to the maybe_nag_for_plugin() method of the WPCom_Theme_Updater class?
I have tried to change the content of updater.php, but I don’t really know what I am doing. I have got some ideas from these links, but cant figure out the right fix:
https://wordpress.stackexchange.com/questions/286332/php-deprecated-non-static-method-should-not-be-called-statically
https://stackoverflow.com/questions/38469828/calling-non-static-method-with-call-user-func-array-in-php
https://stackoverflow.com/questions/19693946/non-static-method-should-not-be-called-statically -
If I in public_html/wp-content/themes/dyad-2-wpcom/inc/updater.php change
public function maybe_nag_for_plugin() {
to
public static function maybe_nag_for_plugin() {Before I also changed a lot of “self::” to “(new self)->” in that file, so it is now like this: https://justpaste.it/7ze4s
With “public static function maybe_nag_for_plugin()” and changing a lot of “self::” to “(new self)->” it now works with PHP 8.1. Until it gets updated ;)
So I still need to ask the author to do similar fixes, so it will continue to work in the future. PHP 7.4 is end of life in November.
- The topic ‘Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme’ is closed to new replies.