I wrote this function that allows the user to view the date of the last login (not the current login). Now I would also like to show the location and device with which the login was made. I tried to search but could not find any solution to my problem. Can anyone shed some light on this? I appreciate any help.
// Function that set last login
add_action('wp_login', 'set_last_login', 0, 2);
function set_last_login($login, $user) {
$user = get_user_by('login',$login);
$time = current_time( 'timestamp' );
$last_login = get_user_meta( $user->ID, '_last_login', 'true' );
if(!$last_login) {
update_user_meta( $user->ID, '_last_login', $time );
}
else {
update_user_meta( $user->ID, '_last_login_prev', $last_login );
update_user_meta( $user->ID, '_last_login', $time );
}
}
// Function that get last login
function get_last_login($user_id, $prev = null) {
$last_login = get_user_meta($user_id);
$time = current_time( 'timestamp' );
if(isset($last_login['_last_login_prev'][0]) && $prev) {
$last_login = get_user_meta($user_id, '_last_login_prev', 'true' );
}
else if(isset($last_login['_last_login'][0])) {
$last_login = get_user_meta($user_id, '_last_login', 'true' );
}
else {
update_user_meta( $user_id, '_last_login', $time );
$last_login = $last_login['_last_login'][0];
} return $last_login;
}
Trying to get something like this 
source https://stackoverflow.com/questions/73934145/wordpress-how-to-get-device-type-and-last-login-location-with-php
No comments:
Post a Comment