Restrict access to admin menu pages in wordpress -
i trying find way limit access admin menu pages specific admins. far have managed hide pages admins not primary admin if enter url page,they directed page.
add_action( 'admin_init', 'my_remove_menu_pages'); function my_remove_menu_pages() { global $user_id; if ( current_user_can( 'administrator' ) && $user_id !== 1 ) { remove_menu_page( 'admin.php?page=settings' ); remove_menu_page( 'plugins.php' ); //remove_menu_page( 'authorhreview' ); }
}
i have been doing lot of reading can't seem come solution. awesome.thanks in advance.
do not pass role name current_user_can(), not guaranteed work correctly..
see : https://core.trac.wordpress.org/ticket/22624
function appthemes_check_user_role( $role, $user_id = null ) { if ( is_numeric( $user_id ) ) $user = get_userdata( $user_id ); else $user = wp_get_current_user(); if ( empty( $user ) ) return false; return in_array( $role, (array) $user->roles ); } //example use current user if ( appthemes_check_user_role( 'customer' ) _e( "you've got access dude!", 'appthemes' ); else _e( "sorry man, no luck.", 'appthemes' ); //example use specific user $user_id = 23; if ( appthemes_check_user_role( 'customer', $user_id ) _e( "you've got access dude!", 'appthemes' ); else _e( "sorry man, no luck.", 'appthemes' );
Comments
Post a Comment