How to use add_action to hook a static method from other Class How to use add_action to hook a static method from other Class wordpress wordpress

How to use add_action to hook a static method from other Class


Your class, Test, is namespaced however you aren't using any namespace when calling add_action.

Update this:

add_action('register_new_user', array('Test','auto_signin'),20);

To this:

add_action( 'register_new_user', array( 'MyTest\Test', 'auto_signin' ), 20 );


I read Wordpress Plugin API Reference, but I cannot find any action named register_new_user, so you must be using a custom hook.

However, the method will be executed if and only if it is hooked and this hook should a corresponding do_action hook.

See this code:

class PluginTest {    function __construct(){    }    public static function insertNew(){        echo 'Hi!';        die();    }}do_action('custom_admin_notices');add_action( 'custom_admin_notices', array('PluginTest', 'insertNew'), 20);global $wp_filter;var_dump($wp_filter['custom_admin_notices']);

If the do_action line is commented, you can still see the hook in the global variable while the method won't be executed. So check whether the line containing do_action is executed.