• I have created a plugin to bypass the admin role but it does not work, admin still limited..

    here is the code I used:

    <?php
    function pcl_bypass_roles( $user_id ) {
    	$whitelist = array( 'administrator', 'editor' ); // Provide an array of roles to bypass
    	$user      = get_userdata( $user_id );
    	$roles     = empty( $user->roles ) ? array() : $user->roles;
    	$intersect = array_intersect( $roles, $whitelist );
    
    	if ( ! empty( $intersect ) ) {
    		return false;
    	}
    
    	return true;
    }
    add_filter( 'pcl_prevent_concurrent_logins', 'pcl_bypass_roles' );
    
    ?>

    https://www.ads-software.com/plugins/prevent-concurrent-logins/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Frankie Jarrett

    (@fjarrett)

    Hi Michael!

    Turns out there was a bug in my example code, sorry about that! I have updated the FAQ accordingly.

    Just update the $user line to:

    $user = get_user_by( 'id', absint( $user_id ) );
    
    Thread Starter Michael Junker

    (@mjunker)

    updated my plugin to omit admins as follows

    function pcl_bypass_roles( $user_id ) {
    	$whitelist = array( 'administrator', 'editor' ); // Provide an array of roles to bypass
    	$user      = get_user_by( 'id', absint( $user_id ) );
    	$roles     = empty( $user->roles ) ? array() : $user->roles;
    	$intersect = array_intersect( $roles, $whitelist );
    
    	if ( ! empty( $intersect ) ) {
    		return false;
    	}
    
    	return true;
    }
    add_filter( 'pcl_prevent_concurrent_logins', 'pcl_bypass_roles' );

    once activated no one is limited any more not even subscribers.

    Plugin Author Frankie Jarrett

    (@fjarrett)

    Hmmm OK I will try to replicate the problem…

    Plugin Author Frankie Jarrett

    (@fjarrett)

    Hi Michael, looks like I forgot to add the first param.

    Please give this try:

    function pcl_bypass_roles( $prevent, $user_id ) {
        $whitelist = array( 'administrator', 'editor' ); // Provide an array of roles to bypass
        $user      = get_user_by( 'id', absint( $user_id ) );
        $roles     = empty( $user->roles ) ? array() : $user->roles;
        $intersect = array_intersect( $roles, $whitelist );
    
        if ( ! empty( $intersect ) ) {
            return false;
        }
    
        return $prevent;
    }
    add_filter( 'pcl_prevent_concurrent_logins', 'pcl_bypass_roles', 10, 2 );
    
    Thread Starter Michael Junker

    (@mjunker)

    that worked Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Admin bypass’ is closed to new replies.