Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active June 25, 2025 23:30
Show Gist options
  • Save lukecav/b27c6c64660910f61f7e31277a69b583 to your computer and use it in GitHub Desktop.
Save lukecav/b27c6c64660910f61f7e31277a69b583 to your computer and use it in GitHub Desktop.
Track Last Login Time and Update User ACF Field
[
{
"key": "group_685c37b820182",
"title": "User Login Info",
"fields": [
{
"key": "field_685c37bd7d63f",
"label": "Last Login Time",
"name": "last_login_time",
"aria-label": "",
"type": "date_time_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "m\/d\/Y g:i a",
"return_format": "m\/d\/Y g:i a",
"first_day": 1,
"allow_in_bindings": 0
}
],
"location": [
[
{
"param": "user_form",
"operator": "==",
"value": "all"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"show_in_rest": 0
}
]
add_action('wp_login', 'track_user_last_login', 10, 2);
function track_user_last_login($user_login, $user) {
if (!function_exists('update_field')) {
return; // ACF not active
}
$user_id = $user->ID;
$current_time = current_time('Y-m-d H:i:s');
// Update ACF field (saves to usermeta)
update_field('last_login_time', $current_time, 'user_' . $user_id);
}