WordPress admin notice in plugin function

Your problem is pretty simple. Your callback for this hook is not a simple function but some method of a class.

If you add action like this:

add_action('admin_notices', 'simple_notice');

you tell WP that there is some simple function called simple_notice and it should be called when hook admin_notices is processed. But… There is no such function anywhere in your code.

The function you want to call is method in your class, so you have to pass not only the name of function, but also object of given class, so WP is able to call this method. (And you’ve done it correctly in __construct).

This line works

add_action('admin_notices', array($this, 'simple_notice')); // This works

because the method is passed with full details – as an array describing object and it’s method to call.

Leave a Comment