Forum Replies Created

Viewing 1 replies (of 1 total)
  • WebMaestroFr, you can prevent the Editor from accessing the “admin” user.php and user-edit.php pages.

    <?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.' );
    
            }
        }
    
    }
    ?>
Viewing 1 replies (of 1 total)