CALL_USER_FUNC_ARRAY()要求参数1是有效的回调函数

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

class mafongroup_admin {

    public function __construct() {
        add_action(\'admin_menu\',\'mafongroup_admin_menu\');
    }

    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\');
        }
    }
}

function mafongroup_admin_menu_function(){
    echo "<h1>TESTING</h1>";
}


new mafongroup_admin();
这使我在声明“call\\u user\\u func\\u array()期望参数1是有效的回调函数”时出错。有人能帮忙吗?

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

你必须改变这个add_action(\'admin_menu\',\'mafongroup_admin_menu\');add_action(\'admin_menu\',array( $this, \'mafongroup_admin_menu\' ) );. 因为你在这里调用一个类方法。所以你必须给班级提供参考。

如果你把public 在声明之前mafongroup_admin_menu() 功能,它将更具可读性,并将在未来有所帮助,我认为。请参见下面更新的课程代码-

class mafongroup_admin {

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

    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\');
        }
    }
}

function mafongroup_admin_menu_function(){
    echo "<h1>TESTING</h1>";
}


new mafongroup_admin();
希望有帮助。