PluginProbe
Users Registration Date – Sortable Users Column / trunk
Users Registration Date – Sortable Users Column vtrunk
trunk 1.0 1.0.1 1.1.0
users-registered-list / users-registered-list.php

users-registered-list.php in Users Registration Date – Sortable Users Column trunk, at users-registered-list.php

114 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Users Registration Date
4 * Plugin URI: https://ovirium.com
5 * Description: New sortable "Registered" date column on the Users page in wp-admin area.
6 * Author: Slava Abakumov
7 * Author URI: https://ovirium.com
8 * Version: 1.1.0
9 * Requires at least: 5.3
10 * Requires PHP: 7.4
11 * Text Domain: users-registered-list
12 * License: GPL-2.0-or-later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 *
15 * This plugin is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 2 of the License, or
18 * any later version.
19 *
20 * This plugin is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this plugin. If not, see <https://www.gnu.org/licenses/>.
27 */
28
29 if ( ! defined( 'ABSPATH' ) ) {
30 exit;
31 }
32
33 /**
34 * Add Reg column to users list in admin area
35 *
36 * @since 1.0.0
37 *
38 * @param array $column The list of columns.
39 */
40 function url_modify_user_table( $column ) {
41
42 $column['reg_date'] = __( 'Registered', 'users-registered-list' );
43
44 return $column;
45 }
46
47 add_filter( 'manage_users_columns', 'url_modify_user_table' );
48
49 /**
50 * Display an actual value in a table of users.
51 *
52 * @since 1.0.0
53 *
54 * @param string $val Expected default value.
55 * @param string $column_name Column name we should check.
56 * @param int $user_id ID of a user we are checking.
57 */
58 function url_modify_user_table_row( $val, $column_name, $user_id ) {
59
60 if ( $column_name !== 'reg_date' ) {
61 return $val;
62 }
63
64 $user = get_userdata( $user_id );
65
66 if ( ! $user ) {
67 return $val;
68 }
69
70 // The registration date is stored in UTC, so pin the timezone when parsing.
71 $timestamp = strtotime( $user->user_registered . ' +0000' );
72
73 if ( ! $timestamp ) {
74 return $val;
75 }
76
77 $date_format = get_option( 'date_format', 'F j, Y' );
78 if ( empty( $date_format ) ) {
79 $date_format = 'F j, Y';
80 }
81
82 $time_format = get_option( 'time_format', 'g:i a' );
83 if ( empty( $time_format ) ) {
84 $time_format = 'g:i a';
85 }
86
87 // The dotted underline and help cursor hint that the date is hoverable.
88 return sprintf(
89 '<span title="%1$s" style="text-decoration: underline dotted; text-underline-offset: 2px; cursor: help;">%2$s</span>',
90 /* translators: %s - human-readable time difference, e.g. "3 years". */
91 esc_attr( sprintf( __( '%s ago', 'users-registered-list' ), human_time_diff( $timestamp ) ) ),
92 // wp_date() converts the UTC timestamp into the site timezone from Settings > General.
93 esc_html( wp_date( $date_format . ' (' . $time_format . ')', $timestamp ) )
94 );
95 }
96
97 add_filter( 'manage_users_custom_column', 'url_modify_user_table_row', 10, 3 );
98
99 /**
100 * Make the column sortable.
101 *
102 * @since 1.0.0
103 *
104 * @param array $sortable The list of sortable columns.
105 */
106 function url_modify_user_table_sortable( $sortable ) {
107
108 $sortable['reg_date'] = 'user_registered';
109
110 return $sortable;
111 }
112
113 add_filter( 'manage_users_sortable_columns', 'url_modify_user_table_sortable' );
114