你必须改变这个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();
希望有帮助。