Your Uncommonly Amazing WordPress Tech Partner

The Problem

You're having a course WordPress website or some other kind of subscription based WordPress site? And users are able to share their account with their friends or basically anyone, which makes it free for them. But you don't want that.

You want to allow only one person to be logged in per account? How do you do that? It is actually very simple. I will explain in detail below how to do it yourself!

The Solution

All you need to do is add a custom function to your theme.

Here's what you'll need:

  1. WordPress Website.
  2. My Custom Functions Plugin installed.

Installing and Activating “My Custom Functions” Plugin

1 – In your WordPress Dashboard navigate to Plugins and click Add New.

add new e1535220315831 - Only one login per user

2 – Search for “My Custom Functions” Plugin.

custom functions 1024x560 - Only one login per user

3 – Locate My Custom Functions plugin and click Install Now.

install 1024x533 - Only one login per user

4 – Click Activate.

activate 1024x507 - Only one login per user

 

 

Adding a Function

1 – After successful installation, navigate to Settings => PHP Inserter.

php inserter - Only one login per user

2 – Paste this code:

function only_one_login() {
    $token = wp_get_session_token();
    if ( $token ) {
        $manager = WP_Session_Tokens::get_instance( get_current_user_id() );
        $manager->destroy_others( $token );
    }
}
add_action('init', 'only_one_login');

Here:

paste here 1024x647 - Only one login per user

3 – Click “ON” button.

on 1024x603 - Only one login per user

4 – Click “Save Changes” button.

save 1024x588 - Only one login per user

That's it! You have successfully implemented a function that prevents more than one one user to be logged in at a time.

You may also enjoy...

WordPress based membership sites have certain requirements, and make use of certain applications that, in my experience, makes most of the popular hosting providers a poor choice.

Melodie Moore receives 1,000 job applications every month for Business Tech Ninjas, her WordPress agency specializing in membership and eLearning platforms. After 10 years, she’s learned something most agencies miss:

Jen Santos had a decade of event tech experience and watched most of it disappear overnight. The pandemic didn’t just pause the events industry. It displaced the people who knew

Learn how to change the color and style of the password strength meter on the MemberPress checkout registration form.

Leave a Reply

Your email address will not be published. Required fields are marked *