Created
June 10, 2013 02:54
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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