I am developing a theme for my website. As soon as I activated the theme, the following errors/warnings shows up on the top of the admin panel on every page.
Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method WPEditorAdmin::removeDefaultEditorMenus() should not be called statically in C:Users...wp-includesplugin.php on line 406
Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method WPEditorAdmin::buildAdminMenu() should not be called statically in C:Users...wp-includesplugin.php on line 406
Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method WPEditorAdmin::addThemesPage() should not be called statically in C:Users...wp-includesplugin.php on line 406
Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method WPEditorAdmin::editorStylesheetAndScripts() should not be called statically in C:Users...wp-includesplugin.php on line 406
I am wondering how do I solve these errors and not have this happen anymore?
Here’s a screenshot.
So you have your code in a class, let’s say it looks like this…
Now you try to hook it into something…
What happens is when the
init
hook fires, WordPress tries to call your method. It would similar to if you just wrote this…But PHP doesn’t like that because you haven’t declare you method
static
, that is, able to be used without an instance of its container class (like the example directly above).This makes sense, what if you used
$this
in your method? Calling it statically would cause a runtime error saying that$this
was being used outside an object context.You can remove the errors by declaring your method static…
Or using an instance of your class as the first element of the array the callable argument of
add_action
.The above is just an example there are many different ways to instantiate a class in a WordPress theme/plugin.