2

I've created a role:

$role = add_role( 'role', 'role', array('read' => true) );

and so created a cap:

$role->add_cap( 'cap' );

after this I'd created a submenu in admin menu with 'cap' as capability argument. So the problem is that the user with 'role' role can see the submenu but the site admin can't see the submenu, so the question is: I have to add 'cap' to admin role ? isn't it automatically ?

5

A new capability has to be explicitly added to either a role or a user. In your case if you want all administrators to have 'cap' capability you will add it to 'administrator' role:

$role = get_role( 'administrator' );
$role->add_cap( 'cap' );

If you want a specific administrator only to have 'cap' capability then you add it to this particular user:

$user = new WP_User( $user_id ); // $user_id = id of your administrator user
$user->add_cap( 'cap' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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