Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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