AnswerBun.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!

Related Questions

where is admin footer?

1  Asked on December 8, 2021 by alif-azhar

     

Remove wpautop from retrieve_password_message

1  Asked on December 8, 2021 by scooterlord

 

WordPress admin display post type tags as checkbox

1  Asked on December 8, 2021 by the-grimmer

   

Sort by page information by Ascending Numbers

1  Asked on December 6, 2021 by owen-oneill

       

Multiple meta_query not returning rows

0  Asked on December 6, 2021 by ookmnnsocjvpkcbnml

   

How to add widget in main menu

1  Asked on December 4, 2021 by mohammad-kashif

       

Improving wpdb queries with large data

1  Asked on December 3, 2021 by dcp3450

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir