plugins - add_submenu_page returns null

After creating a parent admin menu item, which works fine, I fail to add a submenu page. Trying to var_dump the return v

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
  • There is no var_dump in your code, can you adjust it to demonstrate how you tested the return value of add_submenu_page? Is there a reason you don't use the return value of add_menu_page? – Tom J Nowell Commented Mar 2, 2020 at 0:17
Add a comment  | 

1 Answer 1

Reset to default 1

Your 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

相关推荐

  • plugins - add_submenu_page returns null

    After creating a parent admin menu item, which works fine, I fail to add a submenu page. Trying to var_dump the return v

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信