Changeset 3299122
- Timestamp:
- 05/23/2025 05:26:21 AM (10 months ago)
- Location:
- last-login-info/trunk
- Files:
-
- 2 edited
-
last-login-info.php (modified) (5 diffs)
-
readme.txt (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
last-login-info/trunk/last-login-info.php
r3298796 r3299122 4 4 * Plugin Name: Last Login Info 5 5 * Description: Adds a column in the Users screen to show the last login date of each user. 6 * Version: 1.1.06 * Version: 2.0.0 7 7 * Author: Hardik 8 8 * Author URI: https://profiles.wordpress.org/hardikhuptechdev/ … … 44 44 $roles = wp_roles()->roles; 45 45 $settings = lastlogininfo_get_settings(); 46 46 47 ?> 47 48 <div class="wrap"> … … 76 77 <?php submit_button(); ?> 77 78 </form> 79 80 <hr> 81 82 <form method="post"> 83 <?php wp_nonce_field('lastlogininfo_export_csv', 'lastlogininfo_nonce'); ?> 84 <input type="submit" name="lastlogininfo_export" class="button button-primary" value="<?php esc_attr_e('Export Last Login to CSV', 'last-login-info'); ?>"> 85 <input type="submit" name="lastlogininfo_reset" class="button button-secondary" onclick="return confirm('Are you sure you want to delete all last login records?');" value="<?php esc_attr_e('Reset Login Data', 'last-login-info'); ?>"> 86 </form> 78 87 </div> 79 88 <?php … … 86 95 } 87 96 88 // Record last login 97 // Handle Export and Reset 98 add_action('admin_init', 'lastlogininfo_handle_export_or_reset'); 99 function lastlogininfo_handle_export_or_reset() 100 { 101 if (! current_user_can('manage_options') || ! isset($_POST['lastlogininfo_nonce'])) { 102 return; 103 } 104 105 if (! wp_verify_nonce($_POST['lastlogininfo_nonce'], 'lastlogininfo_export_csv')) { 106 return; 107 } 108 109 if (isset($_POST['lastlogininfo_export'])) { 110 $users = get_users(); 111 header('Content-Type: text/csv'); 112 header('Content-Disposition: attachment; filename="last-login-export.csv"'); 113 $output = fopen('php://output', 'w'); 114 fputcsv($output, ['Username', 'Email', 'Roles', 'Last Login']); 115 116 foreach ($users as $user) { 117 $timestamp = get_user_meta($user->ID, 'last_login', true); 118 $login = $timestamp ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $timestamp) : 'Never'; 119 fputcsv($output, [$user->user_login, $user->user_email, implode(', ', $user->roles), $login]); 120 } 121 122 fclose($output); 123 exit; 124 } 125 126 if (isset($_POST['lastlogininfo_reset'])) { 127 $users = get_users(); 128 foreach ($users as $user) { 129 delete_user_meta($user->ID, 'last_login'); 130 } 131 wp_safe_redirect(admin_url('options-general.php?page=last-login-info&reset=1')); 132 exit; 133 } 134 } 135 136 // Record login 89 137 add_action('wp_login', 'lastlogininfo_record_last_login', 10, 2); 90 138 function lastlogininfo_record_last_login($user_login, $user) 91 139 { 92 140 $settings = lastlogininfo_get_settings(); 93 $excluded_roles = $settings['excluded_roles'];94 141 foreach ($user->roles as $role) { 95 if (in_array($role, $ excluded_roles, true)) {142 if (in_array($role, $settings['excluded_roles'], true)) { 96 143 return; 97 144 } 98 145 } 99 100 146 update_user_meta($user->ID, 'last_login', current_time('timestamp')); 101 147 } 102 148 103 // Ad dcolumn149 // Admin column 104 150 add_filter('manage_users_columns', 'lastlogininfo_add_last_login_column'); 105 151 function lastlogininfo_add_last_login_column($columns) … … 109 155 } 110 156 111 // Display column112 157 add_filter('manage_users_custom_column', 'lastlogininfo_show_last_login', 10, 3); 113 158 function lastlogininfo_show_last_login($output, $column_name, $user_id) 114 159 { 115 160 if ('last_login' === $column_name) { 161 $user = get_userdata($user_id); 162 $settings = lastlogininfo_get_settings(); 163 foreach ($user->roles as $role) { 164 if (in_array($role, $settings['excluded_roles'], true)) { 165 return __('Excluded', 'last-login-info'); 166 } 167 } 168 116 169 $timestamp = get_user_meta($user_id, 'last_login', true); 117 170 if ($timestamp) { 118 $settings = lastlogininfo_get_settings();119 171 if ($settings['date_format'] === 'full') { 120 172 return date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $timestamp); 121 173 } else { 122 174 $time_diff = human_time_diff($timestamp, current_time('timestamp')); 123 // translators: %s is a human-readable time difference (e.g., "2 days")124 175 return sprintf(__('%s ago', 'last-login-info'), $time_diff); 125 176 } -
last-login-info/trunk/readme.txt
r3298796 r3299122 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.2 7 Stable tag: 1.1.07 Stable tag: 2.0.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Displays the last login timestamp of each user in the WordPress admin Users table, with a settings page for customization.11 Displays the last login timestamp of each user in the WordPress admin Users table, with tools to export and manage login data. 12 12 13 13 == Description == … … 17 17 This plugin adds a "Last Login" column to the Users table in the WordPress admin. It tracks and displays each user's last login time, with either human-readable formatting (e.g., "2 days ago") or full date/timestamp. The column is sortable, making it easier to find inactive users. 18 18 19 A simple settings page is available under **Settings → Last Login Info**, where you can choose the date display format and exclude specific user roles from being tracked.19 The settings page under **Settings → Last Login Info** allows you to customize the date format, exclude roles, export data to CSV, or reset all login records. 20 20 21 21 == Features == … … 25 25 * Choose between human-readable or full timestamp display. 26 26 * Exclude specific roles from being tracked (e.g., Administrator). 27 * Export all user logins to CSV. 28 * Reset all login tracking data. 27 29 * Sortable column by last login time. 28 30 * Lightweight, no bloat. … … 33 35 2. Activate the plugin through the 'Plugins' screen in WordPress. 34 36 3. Go to "Users" in the WordPress admin — you’ll see a new "Last Login" column. 35 4. Visit **Settings → Last Login Info** to configure display options.37 4. Visit **Settings → Last Login Info** to configure display and export options. 36 38 37 39 == Frequently Asked Questions == … … 47 49 = Can I reset the login data? = 48 50 49 Not yet. This may be added in a future update. You can currently remove the `last_login` user meta manually via custom code or plugins like WP-CLI or Advanced Custom Fields.51 Yes, go to Settings → Last Login Info and click the "Reset Login Data" button. 50 52 51 = = Screenshots ==53 = Can I export login data? = 52 54 53 1. Last Login column in the Users admin table. 54 2. Settings page with display and role options. 55 Yes, the plugin provides a CSV export of all users and their last login details. 55 56 56 57 == Changelog == 58 59 = 2.0.0 = 60 * Added a Reset Login Data button to clear all last login data for users. 61 * Added a CSV Export feature to download usernames, emails, roles, and last login times. 57 62 58 63 = 1.1.0 = … … 66 71 == Upgrade Notice == 67 72 68 = 1.1.0 = 69 Adds a settings page with date format selection and role exclusion features. 70 71 = 1.0.0 = 72 Initial release of Last Login Info. 73 = 2.0.0 = 74 Major update: Reset and Export tools added to the settings page.
Note: See TracChangeset
for help on using the changeset viewer.