Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 14, 2021 20:01
Show Gist options
  • Save jorpdesigns/7f0b013f4215e1c34f3fb3f853ad638e to your computer and use it in GitHub Desktop.
Save jorpdesigns/7f0b013f4215e1c34f3fb3f853ad638e to your computer and use it in GitHub Desktop.
Snippet to set custom login limit
<?php
// Uses Loggedin – Limit Active Logins plugin: https://wordpress.org/plugins/loggedin/
add_filter( 'loggedin_reached_limit', 'custom_login_limits', 10, 3 );
function custom_login_limits($reached, $user_id, $count) {
// Check if user has custom limits and get value (fields added via ACF)
$unlimited_query = get_field('unlimited_logins', 'user_' . $user_id );
$user_custom_limit = get_field('logins_limit', 'user_' . $user_id );
if ( (!$unlimited_query) && ($user_custom_limit) ) {
$reached = $count >= $user_custom_limit;
}
return $reached;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment