Last active
February 20, 2026 20:54
-
-
Save lukecav/b27c6c64660910f61f7e31277a69b583 to your computer and use it in GitHub Desktop.
Track Last Login Time and Update User ACF Field
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
| [ | |
| { | |
| "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 | |
| } | |
| ] |
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
| 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); | |
| } |
Comments are disabled for this gist.