TransWikia.com

Removing add new pages form editor role

WordPress Development Asked on December 5, 2020

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

}

One Answer

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

Answered by Daniel Fonda on December 5, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP