Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created November 11, 2022 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/96e60a63a79745428f7423234c8b726d to your computer and use it in GitHub Desktop.
Save pbrocks/96e60a63a79745428f7423234c8b726d to your computer and use it in GitHub Desktop.
Record date and time information at login.
<?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