-
Notifications
You must be signed in to change notification settings - Fork 0
/
snoka-user-reg-date.php
54 lines (48 loc) · 1.81 KB
/
snoka-user-reg-date.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Plugin Name: User Registration Date Display
* Plugin URI: http://snoka.ca
* Description: Adds user registration date information to user profiles for admins.
* Version: 1.0
* Author: Snoka Media
* Author URI: http://snoka.ca
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Hook to 'show_user_profile' & 'edit_user_profile' to add custom user meta
add_action('show_user_profile', 'urdd_display_registration_date');
add_action('edit_user_profile', 'urdd_display_registration_date');
/**
* Displays the registration date on user profiles for administrators.
*
* @param WP_User $user User object for the current profile.
*/
function urdd_display_registration_date($user) {
// Check if the current user has the 'administrator' role.
if (!current_user_can('manage_options')) {
return;
}
// Use the site's date and time format settings or default to WordPress format if not set.
$date_format = get_option('date_format') ?: 'F j, Y';
$time_format = get_option('time_format') ?: 'g:i a';
// Combine the date and time formats.
$format = $date_format . ', ' . $time_format;
// Format and escape the user's registration date and time according to site settings.
$registration_date = esc_html(date_i18n($format, strtotime($user->user_registered)));
?>
<h3><?php _e("User Registration Information", "user-registration-date-display"); ?></h3>
<table class="form-table">
<tr>
<th><label for="registration-date"><?php _e("Registration Date and Time", "user-registration-date-display"); ?></label></th>
<td>
<?php
// Display the formatted and escaped registration date and time
echo $registration_date;
?>
</td>
</tr>
</table>
<?php
}