Block Profile Menu From Role: Subscriber

Supplemental 222 views
0
0 Flares 0 Flares ×

Use this snippet to block the profile menu from any user with the role of subscriber & redirect them accordingly.

<?php
// source: http://www.shinephp.com/how-to-block-wordpress-admin-menu-item/
// block profile menu for users with role subscriber

if ( is_user_logged_in() ) {

  if ( current_user_can( 'subscriber' ) ) {

    function so_remove_profile_submenu() {
      global $submenu;
      //remove Your profile submenu item
      unset( $submenu['profile.php'][5] );
    }
    add_action( 'admin_head', 'so_remove_profile_submenu' );
 
    function remove_profile_menu() {
	    global $menu;
	    // remove Profile top level menu
	    unset( $menu[70] );
	}
    add_action( 'admin_head', 'so_remove_profile_menu' );
 
 
    function so_profile_redirect() {
	    $result = stripos( $_SERVER['REQUEST_URI'], 'profile.php' );
		if ($result!==false) {
			wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
		}
	}
	add_action( 'admin_menu', 'so_profile_redirect' );
  }
}
// end of block profile menu for users with role

For Reference:

How to Block WordPress Admin Menu Item

Provided by: Piet Bos
Tagged with:
Posted in Wordpress

Discuss:

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×