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

    (@fjarrett)

    Thank you! I’m glad you are finding the plugin useful for your project.

    Your question is covered in the FAQ section.

    https://wordpress.org/plugins/prevent-concurrent-logins/faq/

    Thread Starter gygaxc

    (@gygaxc)

    Hey!
    I’m not used in programming.. so does it have to look like this?

    function pcl_bypass_group_ids( $prevent, $group_id ) {
    $whitelist = array( 1, 2, 3 ); // Provide an array of group IDs to bypass

    if ( in_array( $group_id, $whitelist ) ) {
    return false;
    }

    return $prevent;
    }
    add_filter( ‘pcl_prevent_concurrent_logins’, ‘pcl_bypass_group_ids’, 10, 2 );

    function pcl_bypass_roles( $prevent, $group_id ) {
    $whitelist = array( ‘administrator’, ‘customer’ ); // Provide an array of roles to bypass
    $group = get_group_by( ‘id’, absint( $group_id ) );
    $roles = empty( $group->roles ) ? array() : $group->roles;
    $intersect = array_intersect( $roles, $whitelist );

    if ( ! empty( $intersect ) ) {
    return false;
    }

    return $prevent;
    }
    add_filter( ‘pcl_prevent_concurrent_logins’, ‘pcl_bypass_roles’, 10, 2 );

    Plugin Author Frankie Jarrett

    (@fjarrett)

    Try this:

    function gygaxc_pcl_bypass_roles( $prevent, $user_id ) {
        $whitelist = array( 'administrator', 'customer' ); // 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', 'gygaxc_pcl_bypass_roles', 10, 2 );
    
    Plugin Author Frankie Jarrett

    (@fjarrett)

    ^ that example uses administrator and customer as the roles to exclude.

    Thread Starter gygaxc

    (@gygaxc)

    Hello! Well, thanks for your answer and sorry for late reply – had some other issues to solve first..

    Hmm.. I made a bit of research and found out the following: The membership plugin uses the default wordpress login process. And the developpers told me that it shoud be possible to use this methode for checking client circles:

    global $wpc_client;
    $client_circles = $wpc_client->cc_get_client_groups_id( get_current_user_id() );

    Do you have any idea to integrate this in your plugin?

    Best regards
    gygaxc

    Plugin Author Frankie Jarrett

    (@fjarrett)

    Hi gygaxc,

    Sorry that would require some custom integration with your plugin/setup which is outside the scope of what I’m able to provide here.

    In the future I will most likely add a Settings screen where roles and users can be explicitly whitelisted with checkboxes.

    Until then the pcl_prevent_concurrent_logins filter in the plugin is fully capable of handling what you need. You will just need to modify the logic I provided in it to make it suitable for your application.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Concurrent login for groups’ is closed to new replies.