wordpress get login sessions count of current user

I have tried to search all over internet and also in the forums of wordpress but have not got an answer for this.

Is there any way to limit the number of login sessions a user can do.

Read More

For example, a free user can login 2 times, a gold member can login 4 times, platinum 6 and so on..

I know how to create user levels, just confused how to limit each user role to specific number of login sessions allowed.

Thanks in advance.

Patrick.

Related posts

Leave a Reply

2 comments

  1. Something like this might work:

    function my_handle_login($username, $user) {
        $login_count = intval(get_user_meta($user->ID, 'my_user_count', true));
    
        $login_count++;
        update_user_meta($user->ID, 'my_user_count', $login_count);
    
        // Handle user status etc. according to $login_count
    }
    add_action('wp_login', 'my_handle_login', 10, 2);
    
  2. It’s very simple.

    1. just add a field with login_count name in user table in DB.
    2. When user logged in you have to check that what’s login_count
      nucmber
    3. If login_count is not over, add 1 to login_count