0

Hi I have set up multisite and I am the super admin. I want to remove the capabilities of "Editors" to add new pages. I made this change to my theme function, which removed what I want it too, however it also removes the button and submenu my Admin user. I have tried to put in an if condition, but not having much luck!

//hide Page
function hide_buttons()
{
    global $current_screen;

    if($current_screen->id == 'page');
    {
        echo '<style>.add-new-h2, a.page-title-action {display: none;}</style>';

    }
    
    !current_user_can('publish_posts'))
}
add_action('admin_head','hide_buttons'); // removes the "add new" button on Pages page.


if( current_user_can('editor') ) {
    
    add_action( 'admin_menu', function () {
        remove_submenu_page( 'edit.php?post_type=page', 'post-new.php post_type=page' );  //removes the sub page "add new" in Admin side bar for editor
    }, 999);

}
3
  • 1
    editor can't add pages, but can they edit pages? Nov 30, 2017 at 8:06
  • yes they should be able to edit exiting pages, just not add new ones.
    – Paul
    Nov 30, 2017 at 8:51
  • noting that removing the page doesn't really solve the problem as no capabilities are removed, so the REST API/XMLRPC etc will still publish pages if requested, and you can open the post editor but with the post_type parameter in the URL. All these things should dissapear for users who don't have those capabilities
    – Tom J Nowell
    Jul 6, 2023 at 13:54

1 Answer 1

0

Ok so few things.. there's a pretty well coded plugin that handles user roles and permissions: https://wordpress.org/plugins/user-role-editor/

If you'd like to do this programatically though, you should:

    <?php
function wpcodex_set_capabilities(){
      global $wp_roles; // global class wp-includes/capabilities.php
      $role = 'editor';
      $cap = 'publish_pages';
      $wp_roles->remove_cap( $role, $cap ); 
}
add_action( 'init', 'wpcodex_set_capabilities' );
    ?>

Lmk if that does it :)

2
  • Thanks Daniel, I gave that a go, but hasn't done the trick. I might have to go the plugin route soon! I just couldn't find any that worked, but I'll check out the link you supplied.
    – Paul
    Nov 30, 2017 at 8:58
  • you can add/edit a page without publishing it, there's additional things to remove
    – Tom J Nowell
    Jul 6, 2023 at 13:53

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.