Skip to content

Instantly share code, notes, and snippets.

@ataylorme
Created November 17, 2012 23:11
Show Gist options
  • Save ataylorme/4101237 to your computer and use it in GitHub Desktop.
Save ataylorme/4101237 to your computer and use it in GitHub Desktop.
Restricted admin menu by user ID
/* ========== START RESTICTED ADMIN MENU ACCESS ========== */
if( !function_exists('my_restricted_menu_access') ):
function my_restricted_menu_access() {
global $menu;
//array of restricted menu items
$restricted = array( __('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins') );
end ($menu);
$current_user = wp_get_current_user();
//array of restricted user IDs
$restrictedUsers = array(2);
foreach( $restrictedUsers as $user):
if( $current_user->ID == $user):
while (prev($menu)):
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
endwhile;
endif;
endforeach;
}//end my_restricted_menu_access
endif;
add_action('admin_menu', 'my_restricted_menu_access');
/* ========== END RESTICTED ADMIN MENU ACCESS ========== */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment