skip to Main Content

I have been using a WordPress plugin which is no longer maintained (livecom). I recently updated the website to PHP8, but this plugin, so long as it is active, now causes a fatal WordPress error. I’d prefer to keep the plugin, even if I have to manually ‘patch’ it for the time being.

I believe I can trace the error to this:

PHP Fatal error:  Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method

I note this doesn’t explicitly tell me the line of PHP code which is causing the error – the lines the PHP error log references are in the /wp-includes/class-wp-hook.php, /wp-settings.php and /wp-load.php files, which I don’t believe are themselves directly causing the issue.

Inspecting some of the plugin code, I note it does the following:

function init()
{
    OmAlb_LiveCom_HookHandlers::add_shortcode();
}

There are numerous examples of code like the above. Is this causing the fatal error? If so, how should the code be manually restructured to prevent the fatal errors?

EDIT – This is the full error:

AH01071: Got error ‘PHP message: PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method OmAlb_LiveCom::plugins_loaded() cannot be called statically in /var/www/vhosts/<>/httpdocs/wp-includes/class-wp-hook.php:308
Stack trace:
#0 /var/www/vhosts/<>/httpdocs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()<br>n
#1 /var/www/vhosts/<>/httpdocs/wp-includes/plugin.php(517): WP_Hook->do_action()n
#2 /var/www/vhosts/<>/httpdocs/wp-settings.php(480): do_action()n
#3 /var/www/vhosts/<>/httpdocs/wp-config.php(101): require_once(‘…’)n
#4 /var/www/vhosts/<>/httpdocs/wp-load.php(50): require_once(‘…’)n
#5 /var/www/vhosts/<>/httpdocs/wp-blog-header.php(13): require_once(‘…’)n
#6 /var/www/vhosts/<>/httpdocs/index.php(17): require(‘…’)n
#7 {main}n thrown in /var/www/vhosts/<>/httpdocs/wp-includes/class-wp-hook.php on line 308′, referer: https://<>/<>`

2

Answers


  1. call_user_func_array expects parameter one to be a Callable. Since the error is specifically telling you you need to pass a non-static method, you will need to implement either a user-defined function, such as

    function myCallback() {
        MyClass::myMethod();
    }
    

    or an instance-level method if you have an instance within your reach or an anonymous function.

    Since the plugin is no longer maintained, you need not to worry about future updates and compatibility with them, so you can edit your plugin yourself. If you need further help, you will need to share the relevant part of the plugin you are having a problem with.

    Login or Signup to reply.
  2. Looking at your traceback with the eye of a WordPress dev, #0 and #1 are in the hooks subsystem — the subsystem delivering callbacks to code in plugins and themes. WordPress lives and dies by the hooks subsystem. In your case it, umm, died.

    That hooks subsystem is invoked with this line in wp-settings.php:480.

    do_action( 'plugins_loaded' ); 
    

    That probably means your offending plugin has a line like this someplace in it

    add_action( 'plugins_loaded', 'OmAlb_LiveCom::plugins_loaded' ); 
    

    There may be more parameters in that add_action line.

    That line probably lies within the class definition for OmAlb_LiveCom. And, that same class definition probably has a function definition something like this:

    public function plugins_loaded () {
       /* Some code here. */
    }
    

    That function plugins_loaded must be a static function to match your add_action call. That’s what your error complains about.

    If this works with php 7.x, go back and use it. If you can change the code of that plugin somehow, you might try some things:

    You could try changing the add_action() call to this, to allow the hook to call a member function in the class.

    add_action( 'plugins_loaded', [$this, 'plugins_loaded'] ); 
    

    Or you could redefine plugins_loaded as a static function and use this:

    add_action( 'plugins_loaded','OmAlb_LiveCom::plugins_loaded' ); 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search