• In the code snippet you give in the FAQ, to bypass multiple login control for administator ou editor profiles :

    function loggedin_bypass_roles( $prevent, $user_id ) {
    // Array of roles to bypass.
    $allowed_roles = array( ‘administrator’, ‘editor’ );
    $user = get_user_by( ‘id’, $user_id );
    $roles = ! empty( $user->roles ) ? $user->roles : array();
    return ! empty( array_intersect( $roles, $whitelist ) );
    }
    add_filter( ‘loggedin_bypass’, ‘loggedin_bypass_roles’, 10, 2 );

    I guess there is an error on this line :
    return ! empty( array_intersect( $roles, $whitelist ) );
    that should be :
    return ! empty( array_intersect( $roles, $allowed_roles ) );

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter pixelsing

    (@pixelsing)

    I also propose an alternative to bypass all roles except […] :

    function loggedin_bypass_roles( $prevent, $user_id ) {

    // Array of roles to control.
    $disallowed_roles = array( ‘subscriber’ );

    $user = get_user_by( ‘id’, $user_id );

    $roles = ! empty( $user->roles ) ? $user->roles : array();

    return empty( array_intersect( $roles, $disallowed_roles ) );

    }

    add_filter( ‘loggedin_bypass’, ‘loggedin_bypass_roles’, 10, 2 );

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.