1

I'm currently building a website for a friend and have assigned him the user role of editor. I don't want to give him an administrator role in case he breaks the layout. Anyway, I am using 'add_menu_page()' to add the Appearance > Menus page as an option for the Editor and it is showing up when I log in as an editor role, but when I click on it it says "You do not have sufficient permissions to access this page.

Here is my code:

add_action( 'admin_menu', 'register_my_custom_menu_page' );

function register_my_custom_menu_page(){
    add_menu_page( 'custom menu title', 'custom menu', 'edit_others_posts', 'nav-menus.php' ); 
}

I saw something in the codex that says if you see this message you have hooked in to early. I'm not very familiar with hooks and filters though, so I'm not sure what that means.

2
  • 1
    Did you solve this? Having the same problem
    – chaim
    Commented Jan 19, 2016 at 15:50
  • check my answer Commented Apr 20, 2016 at 8:39

2 Answers 2

1

Run this once, it will be saved in database. You can run it once by adding it to functions.php and reloading the site once.

$user = new WP_User( $user_id ); // the user id you want to have that capability
$user->add_cap( 'edit_others_posts' ); // or any other capability that you want
-1

Try this way :

 add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'nav-menus.php' ); 

For more info visit this link

2
  • That doesn't work for editor because they don't have manage_options capability.
    – chap
    Commented Jul 26, 2014 at 7:37
  • You should be giving the user or role the right capability rather than trying to add the page again. You might make the page link appear in the menu but further capability checks will still fail. Commented Jul 24, 2016 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.