Custom capability to manage menu without edit_theme_options

1 Reply ·

  1. Hi,
    I am looking for a clean solution to assign a specific roles, only the capability to manage menu ( nav-menus.php) and not the capability “edit_theme_options”

    For now, I have resolved with this step but is not clean solution becasue it made the cms not upgradable:

    1) I have create a custom capability called “gestione_menu”;
    2) I have assigned this capability to roles that I want to manage menu;
    3) I have edit the file wp-admin/menu.php ( row 166 of WP 4.9.8) from this

        if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
            $submenu['themes.php'][10] = array( __( 'Menus' ), 'edit_theme_options', 'nav-menus.php' );
        }
    
    
    to this
    
        if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
            $submenu['themes.php'][10] = array( __( 'Menus' ), 'gestione_menu', 'nav-menus.php' );
        }
    

    4) I have edit the file wp-admin/nav-menus.php ( row 22 of WP 4.9.8) from this

    // Permissions Check
    if ( ! current_user_can( 'edit_theme_options' ) ) {
        wp_die(
            '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
            '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
            403
        );
    }
    

    to this

    // Permissions Check
    if ( ! current_user_can( 'gestione_menu' ) ) {
        wp_die(
            '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
            '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
            403
        );
    }
    

    It’s work but I am looking other solution for made the correct ovverride.

    I can’t assign the capability “edit_theme_options” becasue this cap it’s used from other installed plugins and give permission to manage more settings.

    Can anyone, help me?
    Thank you
    Mario