Skip to content

Instantly share code, notes, and snippets.

@nickihastings
Last active August 8, 2021 17:35
Show Gist options
  • Save nickihastings/794eae2ae060a2e38a0f5811defd7fbc to your computer and use it in GitHub Desktop.
Save nickihastings/794eae2ae060a2e38a0f5811defd7fbc to your computer and use it in GitHub Desktop.
How to hide an admin menu in WordPress based on a user role
<?php
/* check if user is administrator - only show downloads menu if is admin */
add_action( 'admin_init', 'nh_remove_menu_pages' );
function nh_remove_menu_pages() {
global $user_ID;
//if the user is NOT an administrator remove the menu for downloads
if ( !current_user_can( 'administrator' ) ) { //change role or capability here
remove_menu_page( 'edit.php?post_type=wpdmpro' ); //change menu item here
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment