CALL_USER_FUNC_ARRAY()要求参数1是有效的回调,函数‘-’找不到或函数名无效

时间:2017-01-11 作者:jeff

class mafongroup_admin {

    public function __construct() {
        add_action( \'admin_menu\', array( $this, \'mafongroup_admin_menu\' ) );
        add_action( \'admin_init\', array( $this, \'mafongroup_admin_menu_function\' ));
    }

    public function mafongroup_admin_menu(){
        if ( current_user_can( \'edit_theme_options\' ) ){
            $page_title="MAFON GROUP";
            $menu_title="MAFON GROUP";
            $capability="administrator";
            $menu_slug="mafongroup_admin_settings";
            $function="mafongroup_admin_menu_function";

            $mafongroup_menu_page_creation_method    = \'add_menu_page\';
            $mafongroup_submenu_page_creation_method = \'add_submenu_page\';

            $theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, $function,\'dashicons-image-filter\', \'2.111111\');
        }
    }

    public function mafongroup_admin_menu_function(){
        echo \'do something\';
    }
}

new mafongroup_admin();
为什么调用此方法时出现错误-“call\\u user\\u func\\u array()要求参数1为有效回调,函数“mafongroup\\u admin\\u menu\\u function”未找到或函数名无效”

有人能帮忙吗?

谢谢

杰夫

1 个回复
最合适的回答,由SO网友:CodeMascot 整理而成

和前面的问题一样,如果你调用了任何类方法来引用该类,请回答。所以你需要更换这条线

$theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, $function,\'dashicons-image-filter\', \'2.111111\');
用这个-

$theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, array( $this, $function ),\'dashicons-image-filter\', \'2.111111\');
因此,您的上述代码如下所示-

class mafongroup_admin {

    public function __construct() {
        add_action( \'admin_menu\', array( $this, \'mafongroup_admin_menu\' ) );
        add_action( \'admin_init\', array( $this, \'mafongroup_admin_menu_function\' ));
    }

    public function mafongroup_admin_menu(){
        if ( current_user_can( \'edit_theme_options\' ) ){
            $page_title="MAFON GROUP";
            $menu_title="MAFON GROUP";
            $capability="administrator";
            $menu_slug="mafongroup_admin_settings";
            $function="mafongroup_admin_menu_function";

            $mafongroup_menu_page_creation_method    = \'add_menu_page\';
            $mafongroup_submenu_page_creation_method = \'add_submenu_page\';

            $theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, array( $this, $function ),\'dashicons-image-filter\', \'2.111111\');
        }
    }

    public function mafongroup_admin_menu_function(){
        echo \'do something\';
    }
}

new mafongroup_admin();
希望这有帮助。

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请