Skip to content

Instantly share code, notes, and snippets.

@oterox
Created July 14, 2019 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oterox/9bf4558689777fc458242badcbea5e72 to your computer and use it in GitHub Desktop.
Save oterox/9bf4558689777fc458242badcbea5e72 to your computer and use it in GitHub Desktop.
WordPress Hide admin menu based on user role
<?php
/* check if user is administrator - only show downloads menu if is admin */
add_action( 'admin_init', 'ox_remove_menu_pages' );
function ox_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