Support » Plugins » add_menu_page access to editors

  • I have written a plugin which uses add_menu_page and add_submenu_page with the capability ‘manage_options’.

    This works for the admin dashboard fine.

    How can I get it to work for an editor dashboard ? preferably without giving editors any other capabilities.

Viewing 1 replies (of 1 total)
  • The answer to allowing editors to see custom menus is to change the capabilities in the add_menu_page function.

    Get an editor capability.
    https://codex.wordpress.org/Roles_and_Capabilities

    Look up the proper code
    https://developer.wordpress.org/reference/functions/add_menu_page/

    Looking at the example text from add_menu_page, where it says ‘manage_options’, change it to ‘edit_others_posts’ or another editor capability.

    
    /**
     * Register a custom menu page.
     */
    function wpdocs_register_my_custom_menu_page() {
        add_menu_page(
            __( 'Custom Menu Title', 'textdomain' ),
            'custom menu',
            'manage_options',
            'myplugin/myplugin-admin.php',
            '',
            plugins_url( 'myplugin/images/icon.png' ),
            6
        );
    }
    add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
    
    
Viewing 1 replies (of 1 total)
  • The topic ‘add_menu_page access to editors’ is closed to new replies.