1

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-includes\plugin.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-includes\plugin.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-includes\plugin.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-includes\plugin.php on line 406

I am wondering how do I solve these errors and not have this happen anymore? Here's a screenshot.

enter image description here

1
  • Can you provide your code where you're using add_action or add_filter in relation to removeDefaultEditorMenus? e.g., add_action('SOME_HOOK', array($SOME_OBJ, 'removeDefaultEditorMenus'));
    – akTed
    Commented Jan 18, 2013 at 23:53

1 Answer 1

5

So you have your code in a class, let's say it looks like this...

<?php
class WPSE82245
{
    public function action_init()
    {
        // do stuff
    }
}

Now you try to hook it into something...

add_action('init', 'array('WPSE82245', 'action_init'));

What happens is when the init hook fires, WordPress tries to call your method. It would similar to if you just wrote this...

WPSE82245::action_init();

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...

<?php
class WPSE82245
{
    public static function action_init()
    {
        // do stuff
    }
}

Or using an instance of your class as the first element of the array the callable argument of add_action.

<?php
class WPSE82245
{
    public function action_init()
    {
        // do stuff
    }
}

$cls = new WPSE82245();
add_action('init', array($cls, 'action_init'));

The above is just an example there are many different ways to instantiate a class in a WordPress theme/plugin.

5
  • Where would this be? I don't get it because this started with a blank wordpress theme.
    – devs
    Commented Jan 19, 2013 at 7:15
  • that you developed? Or that you go from somewhere? Without seeing its code, it could be anywhere, but most likely in functions.php. Commented Jan 19, 2013 at 16:48
  • Yeah, it doesn't have anything related to wordpress in the functions.php
    – devs
    Commented Jan 19, 2013 at 21:53
  • Edited with screenshot
    – devs
    Commented Jan 25, 2013 at 2:23
  • Thanks for breaking this down @chrisguitarguy. Saved me some time vs just turning off debug mode :D. It was happening with me while creating a menu page inside of a class, i had to declare the add_menu_page callable function as being static.
    – Radmation
    Commented Sep 13, 2017 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.