// Check if current user is within session limit
if (!apply_filters("is_within_session_limit", true, wp_get_current_user())) {
echo "You are not within the limit :(";
} else {
echo "You are good to go :)";
}
// Whitelist user roles
add_filter("is_within_session_limit", "whitelist_roles", 99, 2);
function whitelist_roles(bool $within, WP_User $user) {
$allowed_roles = array( 'editor', 'administrator', 'author' );
if (array_intersect( $allowed_roles, $user->roles )) {
return true;
}
return $within;
}
// Set limit for user with ID 8 to 10 sessions
add_filter("session_limit", "increase_limit_user", 99, 2);
function increase_limit_user(bool $within, WP_User $user) {
if ( $user->ID == 8 ) {
return 10;
}
return $within;
}
Learn how to protect your WordPress contents from multiple logins with the Session Manager Plugin