0

I want to know if a user with a specific user id has logged in on my wordpress site.How can I achieve this accurately.

  • Unfortunately is_user_logged_in() does not accept any parameter – user2650277 Aug 6 '15 at 12:14
  • is_user_logged_in checks if the current user is logged in, it doesn't have the ability to check arbitrary users – Tom J Nowell Aug 6 '15 at 12:19
  • You may have to be a bit clearer in your question - Do you need to check if the user has ever logged in? Or do you want to be notified every time they log in? Or, do you want to be able to find the time they have last logged in? Unfortunately, there is no way to tell if a user is 'currently logged in', as that's just not how WordPress works. – markmoxx Aug 10 '15 at 15:52
1

You could always try using the wp_login action hook:

function custom_check_for_user($user_login, $user) {
    if($user->ID == 123) { // Where 123 is the particular user's ID
        // Do something here, eg. PHP mail() function
    }
}
add_action('wp_login', 'custom_check_for_user', 10, 2);

Further reading: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_login

| improve this answer | |
  • How do i place this code outside of wp like Mywpsite.com/logincheck.php . Then my other script will use the logincheck as an endpoint – user2650277 Aug 7 '15 at 13:04
0

try this code, it is in user-edit.php :
$sessions = WP_Session_Tokens::get_instance( $profileuser->ID );

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.