Skip to content

Instantly share code, notes, and snippets.

@wkw
Last active March 8, 2016 19:19
Show Gist options
  • Save wkw/2a119a688babed27c512 to your computer and use it in GitHub Desktop.
Save wkw/2a119a688babed27c512 to your computer and use it in GitHub Desktop.
Show WordPress CPT Menu only for specific user
[Removing Menus](http://wordpress.stackexchange.com/questions/28782/possible-to-hide-custom-post-type-ui-menu-from-specific-user-roles)
[get user info](https://codex.wordpress.org/Function_Reference/wp_get_current_user)
<?php
function wpse28782_remove_menu_items() {
$allow_username = 'dev_admin';
$remove_posttype_name = 'something';
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) ) {
return;
}
if( $allow_username !== $current_user->user_login ):
remove_menu_page( 'edit.php?post_type=' . $remove_posttype_name );
endif;
}
}
add_action( 'admin_menu', 'wpse28782_remove_menu_items' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment