After creating a parent admin menu item, which works fine, I fail to add a submenu page. Trying to var_dump the return value of add_submenu_page() I get 'null'.
My functions are:
/**
* Register the admin menu page
*
* @since 1.0.0
*/
public function add_admin_menu() {
add_menu_page( 'WPQuotes', 'WPQuotes', 'manage_options', 'wp-quotes-plugin', 'wpq_admin_settings_page_main', 'dashicons-networking' );
add_submenu_page( 'wp-quotes-plugin', 'New WPQ Form', 'New WPQ Form', 'manage-options', 'wpq-new-form', 'wpq_admin_settings_page_new_form');
}
public function run_all(){
add_action( 'admin_menu', array($this, 'add_admin_menu'), 10 );
}
After creating a parent admin menu item, which works fine, I fail to add a submenu page. Trying to var_dump the return value of add_submenu_page() I get 'null'.
My functions are:
/**
* Register the admin menu page
*
* @since 1.0.0
*/
public function add_admin_menu() {
add_menu_page( 'WPQuotes', 'WPQuotes', 'manage_options', 'wp-quotes-plugin', 'wpq_admin_settings_page_main', 'dashicons-networking' );
add_submenu_page( 'wp-quotes-plugin', 'New WPQ Form', 'New WPQ Form', 'manage-options', 'wpq-new-form', 'wpq_admin_settings_page_new_form');
}
public function run_all(){
add_action( 'admin_menu', array($this, 'add_admin_menu'), 10 );
}
Share
Improve this question
asked Mar 1, 2020 at 21:54
SamerSamer
1
1
|
1 Answer
Reset to default 1Your code is correct but just you have called wrong capability in
add_submenu_page
.You just need to replace this
'manage_options'
instead of'manage-options'
. And please check it. It's works.
Reference: https://developer.wordpress/reference/functions/add_submenu_page/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744703364a4588907.html
var_dump
in your code, can you adjust it to demonstrate how you tested the return value ofadd_submenu_page
? Is there a reason you don't use the return value ofadd_menu_page
? – Tom J Nowell ♦ Commented Mar 2, 2020 at 0:17