Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardomdornelas/5746247 to your computer and use it in GitHub Desktop.
Save leonardomdornelas/5746247 to your computer and use it in GitHub Desktop.
Prevent the Editor from accessing the "admin" user.php and user-edit.php pages. #wordpress
<?php
add_action( 'admin_init', 'stop_access_admin_profile' );
function stop_access_admin_profile() {
global $pagenow;
if (isset($_REQUEST['user_id'])) {
$user_id = $_REQUEST['user_id'];
} else if (isset($_REQUEST['user'])) {
$user_id = $_REQUEST['user'];
} else {
$user_id = 0;
}
$level = get_user_meta($user_id, 'wp_user_level', true) ;
$user = wp_get_current_user();
$blocked_admin_pages = array('user-edit.php', 'users.php');
if ( in_array( 'editor', $user->roles ) ) {
if( in_array($pagenow, $blocked_admin_pages) && ($level == 10) ) { // 10 corresponds to admin level.
wp_die( 'You cannot access the admin user.' );
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment