Title: Admin bypass
Last modified: August 24, 2016

---

# Admin bypass

 *  Resolved [Michael Junker](https://wordpress.org/support/users/mjunker/)
 * (@mjunker)
 * [11 years ago](https://wordpress.org/support/topic/admin-bypass/)
 * 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://wordpress.org/plugins/prevent-concurrent-logins/](https://wordpress.org/plugins/prevent-concurrent-logins/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Frankie Jarrett](https://wordpress.org/support/users/fjarrett/)
 * (@fjarrett)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/admin-bypass/#post-6139500)
 * Hi Michael!
 * Turns out there was a bug in my example code, sorry about that! I have [updated the FAQ](https://wordpress.org/plugins/prevent-concurrent-logins/faq/)
   accordingly.
 * Just update the `$user` line to:
 *     ```
       $user = get_user_by( 'id', absint( $user_id ) );
       ```
   
 *  Thread Starter [Michael Junker](https://wordpress.org/support/users/mjunker/)
 * (@mjunker)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/admin-bypass/#post-6139501)
 * 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](https://wordpress.org/support/users/fjarrett/)
 * (@fjarrett)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/admin-bypass/#post-6139502)
 * Hmmm OK I will try to replicate the problem…
 *  Plugin Author [Frankie Jarrett](https://wordpress.org/support/users/fjarrett/)
 * (@fjarrett)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/admin-bypass/#post-6139503)
 * 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](https://wordpress.org/support/users/mjunker/)
 * (@mjunker)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/admin-bypass/#post-6139504)
 * that worked Thank you

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Admin bypass’ is closed to new replies.

 * ![](https://ps.w.org/prevent-concurrent-logins/assets/icon-256x256.png?rev=1152517)
 * [Prevent Concurrent Logins](https://wordpress.org/plugins/prevent-concurrent-logins/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/prevent-concurrent-logins/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/prevent-concurrent-logins/)
 * [Active Topics](https://wordpress.org/support/plugin/prevent-concurrent-logins/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/prevent-concurrent-logins/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/prevent-concurrent-logins/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Michael Junker](https://wordpress.org/support/users/mjunker/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/admin-bypass/#post-6139504)
 * Status: resolved