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);

}
  • 1
    editor can't add pages, but can they edit pages? – Mayeenul Islam Nov 30 '17 at 8:06
  • yes they should be able to edit exiting pages, just not add new ones. – Paul Nov 30 '17 at 8:51
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 :)

  • 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 '17 at 8:58

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.