Easily restrict some functions and pages of your WordPress admin and that too without any plugin. So let’s follow this article.

NOTE : Write all the scripts yourself, instead of copy / paste. This will easily understand the structure of the script.

So let’s start with how to restrict the menus of WordPress admin as per user role :


function restrict_wp_menus() {
       $user = wp_get_current_user();

          if( isset( $user->roles[0] ) ) { 
             $current_role = $user->roles[0];
          } else {
            $current_role = 'no_role';
            }
     if( 'contributor' == $current_role ) { 
                  $screen = get_current_screen();
                   $base = $screen->id;


       if( 'dashboard' == $base || 'tools' == $base || 'edit-comments' == $base ) {
                wp_redirect('/') ;
              }
          }
      }
  add_action( 'current_screen', 'restrict_wp_menus' );

 

Comment if the script is not working . Happy Coding

Comments to: How to restrict and Redirect the WordPress Admin menus as per Role

Your email address will not be published. Required fields are marked *

Login

welcom
....

You can make anything by Reading and Writing.
Join Aranjra

Happy

Halloween

Read and Share spooky stories with Aranjra!

Get ₹99 Bonus
On Signup