Skip to content

Instantly share code, notes, and snippets.

@wpmark
Last active September 9, 2017 15:19
Show Gist options
  • Save wpmark/8160972 to your computer and use it in GitHub Desktop.
Save wpmark/8160972 to your computer and use it in GitHub Desktop.
Remove WordPress admin menu items for certain users.
<?php
/* add our function to the admin meny action */
add_action( 'admin_menu', 'pxjn_remove_menus', 999 );
function pxjn_remove_menus() {
/* get the current user id */
$pxjn_current_user_id = $current_user->ID; // get the user ID
/* setup an array of user ids to not be affected */
$pxjn_team_ids = array( 1, 2 );
/* if current user id is not in the allowed array */
if( ! in_array( $pxjn_current_user_id, $pxjn_team_ids ) ) {
/* remove the menu items(s) */
remove_menu_page( 'link-manager.php' );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment