Created
November 11, 2022 14:24
-
-
Save pbrocks/96e60a63a79745428f7423234c8b726d to your computer and use it in GitHub Desktop.
Record date and time information at login.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_login', 'record_current_datetime_at_login', 10, 2 ); | |
/** | |
* Record Time and Date at login as a readable string. | |
* Save in user meta. | |
* | |
* @param string $user_login login_name | |
* @param object $user WP_User object | |
* @return string Date, time, timezone, offset | |
*/ | |
function record_current_datetime_at_login( $user_login, $user ) { | |
$time = date_i18n( get_option( 'date_format' ), time() ) . ' ' . get_option( 'timezone_string' ) . ' ' . date_i18n( get_option( 'time_format' ), time() ) . ' ' . get_option( 'gmt_offset' ) . ' hours offset'; | |
update_user_meta( $user->ID, $user_login . '_last_login_' . $user->ID, $time); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment