private function restrictAdminPanelAccess()
    {
        // Don't restrict anything when doing AJAX or CLI stuff
        if ((defined('DOING_AJAX') && DOING_AJAX) || (defined('WP_CLI') && WP_CLI) || !is_user_logged_in())
        {
            return;
        }

        $data = $this->getData();

        // Don't go further if no setting
        if ( !isset($data['admin_access']) || empty($data['admin_access']) || !is_admin())
        {
            return;
        }

        $access = $data['admin_access'];

        // Is current user's role within our access roles?
        $user = wp_get_current_user();
        $role = $user->roles;
        $role = (count($role) > 0) ? $role[0] : '';
        $isUserIncluded = in_array($role, $access['roles']);

        // Redirect to website home if required
        if (($access['mode'] == 'allow' && !$isUserIncluded)
            || ($access['mode'] == 'forbid' && $isUserIncluded)
        )
        {
            wp_redirect(home_url());
            exit;
        }
    }
private function restrictAdminPanelAccess()
    {
        // Don't restrict anything when doing AJAX or CLI stuff
        if ((defined('DOING_AJAX') && DOING_AJAX) || (defined('WP_CLI') && WP_CLI) || !is_user_logged_in())
        {
            return;
        }

        $data = $this->getData();

        // Don't go further if no setting
        if ( !isset($data['admin_access']) || empty($data['admin_access']) || !is_admin())
        {
            return;
        }

        $access = $data['admin_access'];

        // Is current user's role within our access roles?
        $user = wp_get_current_user();
        $role = $user->roles;
        $role = (count($role) > 0) ? $role[0] : '';
        $isUserIncluded = in_array($role, $access['roles']);

        // Redirect to website home if required
        if (($access['mode'] == 'allow' && !$isUserIncluded)
            || ($access['mode'] == 'forbid' && $isUserIncluded)
        )
        {
            wp_redirect(home_url());
            exit;
        }
    }
private function restrictAdminPanelAccess ( ) { // Don't restrict anything when doing AJAX or CLI stuff if ( ( defined ( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined ( 'WP_CLI' ) && WP_CLI ) || ! is_user_logged_in ( ) ) { return ; } $ data = $ this -> getData ( ) ; // Don't go further if no setting if ( ! isset ( $ data [ 'admin_access' ] ) || empty ( $ data [ 'admin_access' ] ) || ! is_admin ( ) ) { return ; } $ access = $ data [ 'admin_access' ] ; // Is current user's role within our access roles? $ user = wp_get_current_user ( ) ; $ role = $ user -> roles ; $ role = ( count ( $ role ) > 0 ) ? $ role [ 0 ] : '' ; $ isUserIncluded = in_array ( $ role , $ access [ 'roles' ] ) ; // Redirect to website home if required if ( ( $ access [ 'mode' ] == 'allow' && ! $ isUserIncluded ) || ( $ access [ 'mode' ] == 'forbid' && $ isUserIncluded ) ) { wp_redirect ( home_url ( ) ) ; exit ; } }
Restrict access to the wp-admin.
Restrict access to the wp - admin .