0

I have created a new role .Now I want to remove post ,media, setting capability for that role. How can I achieve this?

  • What is your new role name? – prosti Dec 16 '16 at 8:50
  • 1
    do you think: post, media, settings are capabilities? – prosti Dec 16 '16 at 8:55
1

Remove a top level admin menu:

    function custom_menu_page_removing() {
    remove_menu_page( $menu_slug );
}
add_action( 'admin_menu', 'custom_menu_page_removing' );

To remove only certain menu items include only those you want to hide within the function. To remove menus for only certain users you may want to utilize current_user_can().

You can take a look at https://codex.wordpress.org/Function_Reference/remove_menu_page

0

Would you be so kind to try this:

$data = get_userdata( 1 ); // or any other ID where your new role works
if ( !empty( $data) ) {
    $user_caps = $data->allcaps;
    echo '<pre>' . print_r( $user_caps, true ) . '</pre>';
}

You will get the idea of capabilities on your end.

Array
(
    [switch_themes] => 1
    [edit_themes] => 1
    [activate_plugins] => 1
    [edit_plugins] => 1
    [edit_users] => 1
    [edit_files] => 1
    [manage_options] => 1
    [moderate_comments] => 1
    [manage_categories] => 1
    [manage_links] => 1
    [upload_files] => 1
    [import] => 1
    [unfiltered_html] => 1
    [edit_posts] => 1
    [edit_others_posts] => 1
    [edit_published_posts] => 1
    [publish_posts] => 1
    [edit_pages] => 1
    [read] => 1
    [level_10] => 1
    [level_9] => 1
    [level_8] => 1
    [level_7] => 1
    [level_6] => 1
    [level_5] => 1
    [level_4] => 1
    [level_3] => 1
    [level_2] => 1
    [level_1] => 1
    [level_0] => 1
    [edit_others_pages] => 1
    [edit_published_pages] => 1
    [publish_pages] => 1
    [delete_pages] => 1
    [delete_others_pages] => 1
    [delete_published_pages] => 1
    [delete_posts] => 1
    [delete_others_posts] => 1
    [delete_published_posts] => 1
    [delete_private_posts] => 1
    [edit_private_posts] => 1
    [read_private_posts] => 1
    [delete_private_pages] => 1
    [edit_private_pages] => 1
    [read_private_pages] => 1
    [delete_users] => 1
    [create_users] => 1
    [unfiltered_upload] => 1
    [edit_dashboard] => 1
    [update_plugins] => 1
    [delete_plugins] => 1
    [install_plugins] => 1
    [update_themes] => 1
    [install_themes] => 1
    [update_core] => 1
    [list_users] => 1
    [remove_users] => 1
    [promote_users] => 1
    [edit_theme_options] => 1
    [delete_themes] => 1
    [export] => 1
    [view_query_monitor] => 1
    [administrator] => 1
)

Then remove them simple with this code:

// Remove a capability from a specific user.
$user_id = // The ID of the user to remove the capability from.
$user = new WP_User( $user_id );
$user->remove_cap( 'read_private_posts' );

from ref.

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.