author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* List Table API: WP_Users_List_Table class |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Administration |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* Core class used to implement displaying users in a list table. |
0 | 12 |
* |
5 | 13 |
* @since 3.1.0 |
14 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* @see WP_List_Table |
0 | 16 |
*/ |
17 |
class WP_Users_List_Table extends WP_List_Table { |
|
18 |
||
5 | 19 |
/** |
20 |
* Site ID to generate the Users list table for. |
|
21 |
* |
|
22 |
* @since 3.1.0 |
|
23 |
* @var int |
|
24 |
*/ |
|
25 |
public $site_id; |
|
0 | 26 |
|
5 | 27 |
/** |
28 |
* Whether or not the current Users list table is for Multisite. |
|
29 |
* |
|
30 |
* @since 3.1.0 |
|
31 |
* @var bool |
|
32 |
*/ |
|
33 |
public $is_site_users; |
|
34 |
||
35 |
/** |
|
36 |
* Constructor. |
|
37 |
* |
|
38 |
* @since 3.1.0 |
|
39 |
* |
|
40 |
* @see WP_List_Table::__construct() for more information on default arguments. |
|
41 |
* |
|
42 |
* @param array $args An associative array of arguments. |
|
43 |
*/ |
|
44 |
public function __construct( $args = array() ) { |
|
9 | 45 |
parent::__construct( |
46 |
array( |
|
47 |
'singular' => 'user', |
|
48 |
'plural' => 'users', |
|
49 |
'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
50 |
) |
|
51 |
); |
|
0 | 52 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
$this->is_site_users = 'site-users-network' === $this->screen->id; |
0 | 54 |
|
9 | 55 |
if ( $this->is_site_users ) { |
18 | 56 |
$this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0; |
9 | 57 |
} |
0 | 58 |
} |
59 |
||
5 | 60 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
* Checks the current user's permissions. |
5 | 62 |
* |
9 | 63 |
* @since 3.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* @return bool |
5 | 66 |
*/ |
67 |
public function ajax_user_can() { |
|
9 | 68 |
if ( $this->is_site_users ) { |
0 | 69 |
return current_user_can( 'manage_sites' ); |
9 | 70 |
} else { |
0 | 71 |
return current_user_can( 'list_users' ); |
9 | 72 |
} |
0 | 73 |
} |
74 |
||
5 | 75 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
* Prepares the users list for display. |
5 | 77 |
* |
78 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* @global string $role |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* @global string $usersearch |
5 | 82 |
*/ |
83 |
public function prepare_items() { |
|
0 | 84 |
global $role, $usersearch; |
85 |
||
5 | 86 |
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; |
0 | 87 |
|
88 |
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; |
|
89 |
||
9 | 90 |
$per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page'; |
0 | 91 |
$users_per_page = $this->get_items_per_page( $per_page ); |
92 |
||
93 |
$paged = $this->get_pagenum(); |
|
94 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
if ( 'none' === $role ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
$args = array( |
9 | 97 |
'number' => $users_per_page, |
98 |
'offset' => ( $paged - 1 ) * $users_per_page, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
'include' => wp_get_users_with_no_role( $this->site_id ), |
9 | 100 |
'search' => $usersearch, |
101 |
'fields' => 'all_with_meta', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
'number' => $users_per_page, |
9 | 106 |
'offset' => ( $paged - 1 ) * $users_per_page, |
107 |
'role' => $role, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
'search' => $usersearch, |
9 | 109 |
'fields' => 'all_with_meta', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
} |
0 | 112 |
|
9 | 113 |
if ( '' !== $args['search'] ) { |
0 | 114 |
$args['search'] = '*' . $args['search'] . '*'; |
9 | 115 |
} |
0 | 116 |
|
9 | 117 |
if ( $this->is_site_users ) { |
0 | 118 |
$args['blog_id'] = $this->site_id; |
9 | 119 |
} |
0 | 120 |
|
9 | 121 |
if ( isset( $_REQUEST['orderby'] ) ) { |
0 | 122 |
$args['orderby'] = $_REQUEST['orderby']; |
9 | 123 |
} |
0 | 124 |
|
9 | 125 |
if ( isset( $_REQUEST['order'] ) ) { |
0 | 126 |
$args['order'] = $_REQUEST['order']; |
9 | 127 |
} |
0 | 128 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* Filters the query arguments used to retrieve users for the current users list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* @param array $args Arguments passed to WP_User_Query to retrieve items for the current |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* users list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
$args = apply_filters( 'users_list_table_query_args', $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
|
16 | 139 |
// Query the user IDs for this page. |
0 | 140 |
$wp_user_search = new WP_User_Query( $args ); |
141 |
||
142 |
$this->items = $wp_user_search->get_results(); |
|
143 |
||
9 | 144 |
$this->set_pagination_args( |
145 |
array( |
|
146 |
'total_items' => $wp_user_search->get_total(), |
|
147 |
'per_page' => $users_per_page, |
|
148 |
) |
|
149 |
); |
|
0 | 150 |
} |
151 |
||
5 | 152 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
153 |
* Outputs 'no users' message. |
5 | 154 |
* |
155 |
* @since 3.1.0 |
|
156 |
*/ |
|
157 |
public function no_items() { |
|
158 |
_e( 'No users found.' ); |
|
0 | 159 |
} |
160 |
||
5 | 161 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
162 |
* Returns an associative array listing all the views that can be used |
5 | 163 |
* with this table. |
164 |
* |
|
165 |
* Provides a list of roles and user count for that role for easy |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
166 |
* filtering of the user table. |
5 | 167 |
* |
16 | 168 |
* @since 3.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* @global string $role |
5 | 171 |
* |
16 | 172 |
* @return string[] An array of HTML links keyed by their view. |
5 | 173 |
*/ |
174 |
protected function get_views() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
global $role; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
$wp_roles = wp_roles(); |
0 | 178 |
|
19 | 179 |
$count_users = ! wp_is_large_user_count(); |
180 |
||
0 | 181 |
if ( $this->is_site_users ) { |
182 |
$url = 'site-users.php?id=' . $this->site_id; |
|
183 |
} else { |
|
19 | 184 |
$url = 'users.php'; |
0 | 185 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
187 |
$role_links = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
188 |
$avail_roles = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
189 |
$all_text = __( 'All' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
|
19 | 191 |
if ( $count_users ) { |
192 |
if ( $this->is_site_users ) { |
|
193 |
switch_to_blog( $this->site_id ); |
|
194 |
$users_of_blog = count_users( 'time', $this->site_id ); |
|
195 |
restore_current_blog(); |
|
196 |
} else { |
|
197 |
$users_of_blog = count_users(); |
|
198 |
} |
|
199 |
||
200 |
$total_users = $users_of_blog['total_users']; |
|
201 |
$avail_roles =& $users_of_blog['avail_roles']; |
|
202 |
unset( $users_of_blog ); |
|
203 |
||
204 |
$all_text = sprintf( |
|
16 | 205 |
/* translators: %s: Number of users. */ |
206 |
_nx( |
|
207 |
'All <span class="count">(%s)</span>', |
|
208 |
'All <span class="count">(%s)</span>', |
|
209 |
$total_users, |
|
210 |
'users' |
|
211 |
), |
|
212 |
number_format_i18n( $total_users ) |
|
19 | 213 |
); |
214 |
} |
|
215 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
216 |
$role_links['all'] = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
217 |
'url' => $url, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
218 |
'label' => $all_text, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
'current' => empty( $role ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
220 |
); |
16 | 221 |
|
0 | 222 |
foreach ( $wp_roles->get_names() as $this_role => $name ) { |
19 | 223 |
if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) { |
0 | 224 |
continue; |
9 | 225 |
} |
0 | 226 |
|
227 |
$name = translate_user_role( $name ); |
|
19 | 228 |
if ( $count_users ) { |
229 |
$name = sprintf( |
|
230 |
/* translators: 1: User role name, 2: Number of users. */ |
|
231 |
__( '%1$s <span class="count">(%2$s)</span>' ), |
|
232 |
$name, |
|
233 |
number_format_i18n( $avail_roles[ $this_role ] ) |
|
234 |
); |
|
235 |
} |
|
16 | 236 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
237 |
$role_links[ $this_role ] = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
238 |
'url' => esc_url( add_query_arg( 'role', $this_role, $url ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
239 |
'label' => $name, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
'current' => $this_role === $role, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
241 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
|
9 | 244 |
if ( ! empty( $avail_roles['none'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
$name = __( 'No role' ); |
16 | 247 |
$name = sprintf( |
248 |
/* translators: 1: User role name, 2: Number of users. */ |
|
249 |
__( '%1$s <span class="count">(%2$s)</span>' ), |
|
250 |
$name, |
|
251 |
number_format_i18n( $avail_roles['none'] ) |
|
252 |
); |
|
253 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
254 |
$role_links['none'] = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
255 |
'url' => esc_url( add_query_arg( 'role', 'none', $url ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
256 |
'label' => $name, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
257 |
'current' => 'none' === $role, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
258 |
); |
0 | 259 |
} |
260 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
return $this->get_views_links( $role_links ); |
0 | 262 |
} |
263 |
||
5 | 264 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
* Retrieves an associative array of bulk actions available on this table. |
5 | 266 |
* |
16 | 267 |
* @since 3.1.0 |
5 | 268 |
* |
18 | 269 |
* @return array Array of bulk action labels keyed by their action. |
5 | 270 |
*/ |
271 |
protected function get_bulk_actions() { |
|
0 | 272 |
$actions = array(); |
273 |
||
274 |
if ( is_multisite() ) { |
|
9 | 275 |
if ( current_user_can( 'remove_users' ) ) { |
0 | 276 |
$actions['remove'] = __( 'Remove' ); |
9 | 277 |
} |
0 | 278 |
} else { |
9 | 279 |
if ( current_user_can( 'delete_users' ) ) { |
0 | 280 |
$actions['delete'] = __( 'Delete' ); |
9 | 281 |
} |
0 | 282 |
} |
283 |
||
18 | 284 |
// Add a password reset link to the bulk actions dropdown. |
285 |
if ( current_user_can( 'edit_users' ) ) { |
|
286 |
$actions['resetpassword'] = __( 'Send password reset' ); |
|
287 |
} |
|
288 |
||
0 | 289 |
return $actions; |
290 |
} |
|
291 |
||
5 | 292 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
293 |
* Outputs the controls to allow user roles to be changed in bulk. |
5 | 294 |
* |
295 |
* @since 3.1.0 |
|
296 |
* |
|
297 |
* @param string $which Whether this is being invoked above ("top") |
|
298 |
* or below the table ("bottom"). |
|
299 |
*/ |
|
300 |
protected function extra_tablenav( $which ) { |
|
9 | 301 |
$id = 'bottom' === $which ? 'new_role2' : 'new_role'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
$button_id = 'bottom' === $which ? 'changeit2' : 'changeit'; |
9 | 303 |
?> |
0 | 304 |
<div class="alignleft actions"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
<?php if ( current_user_can( 'promote_users' ) && $this->has_items() ) : ?> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
<label class="screen-reader-text" for="<?php echo $id; ?>"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
307 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
309 |
_e( 'Change role to…' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
</label> |
9 | 312 |
<select name="<?php echo $id; ?>" id="<?php echo $id; ?>"> |
313 |
<option value=""><?php _e( 'Change role to…' ); ?></option> |
|
0 | 314 |
<?php wp_dropdown_roles(); ?> |
18 | 315 |
<option value="none"><?php _e( '— No role for this site —' ); ?></option> |
0 | 316 |
</select> |
9 | 317 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
submit_button( __( 'Change' ), '', $button_id, false ); |
0 | 319 |
endif; |
320 |
||
5 | 321 |
/** |
322 |
* Fires just before the closing div containing the bulk role-change controls |
|
323 |
* in the Users list table. |
|
324 |
* |
|
325 |
* @since 3.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* @since 4.6.0 The `$which` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
5 | 329 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
do_action( 'restrict_manage_users', $which ); |
9 | 331 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
</div> |
9 | 333 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* Fires immediately following the closing "actions" div in the tablenav for the users |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
do_action( 'manage_users_extra_tablenav', $which ); |
0 | 343 |
} |
344 |
||
5 | 345 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
346 |
* Captures the bulk action required, and return it. |
5 | 347 |
* |
348 |
* Overridden from the base class implementation to capture |
|
349 |
* the role change drop-down. |
|
350 |
* |
|
16 | 351 |
* @since 3.1.0 |
5 | 352 |
* |
353 |
* @return string The bulk action required. |
|
354 |
*/ |
|
355 |
public function current_action() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
356 |
if ( isset( $_REQUEST['changeit'] ) ) { |
0 | 357 |
return 'promote'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
} |
0 | 359 |
|
360 |
return parent::current_action(); |
|
361 |
} |
|
362 |
||
5 | 363 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
364 |
* Gets a list of columns for the list table. |
5 | 365 |
* |
16 | 366 |
* @since 3.1.0 |
5 | 367 |
* |
16 | 368 |
* @return string[] Array of column titles keyed by their column name. |
5 | 369 |
*/ |
370 |
public function get_columns() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
$columns = array( |
0 | 372 |
'cb' => '<input type="checkbox" />', |
373 |
'username' => __( 'Username' ), |
|
374 |
'name' => __( 'Name' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
'email' => __( 'Email' ), |
0 | 376 |
'role' => __( 'Role' ), |
19 | 377 |
'posts' => _x( 'Posts', 'post type general name' ), |
0 | 378 |
); |
379 |
||
9 | 380 |
if ( $this->is_site_users ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
381 |
unset( $columns['posts'] ); |
9 | 382 |
} |
0 | 383 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
return $columns; |
0 | 385 |
} |
386 |
||
5 | 387 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
388 |
* Gets a list of sortable columns for the list table. |
5 | 389 |
* |
390 |
* @since 3.1.0 |
|
391 |
* |
|
392 |
* @return array Array of sortable columns. |
|
393 |
*/ |
|
394 |
protected function get_sortable_columns() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
$columns = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
'username' => array( 'login', false, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
397 |
'email' => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ), |
0 | 398 |
); |
399 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
return $columns; |
0 | 401 |
} |
402 |
||
5 | 403 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
* Generates the list table rows. |
5 | 405 |
* |
406 |
* @since 3.1.0 |
|
407 |
*/ |
|
408 |
public function display_rows() { |
|
16 | 409 |
// Query the post counts for this page. |
9 | 410 |
if ( ! $this->is_site_users ) { |
0 | 411 |
$post_counts = count_many_users_posts( array_keys( $this->items ) ); |
9 | 412 |
} |
0 | 413 |
|
414 |
foreach ( $this->items as $userid => $user_object ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 ); |
0 | 416 |
} |
417 |
} |
|
418 |
||
419 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
* Generates HTML for a single row on the users.php admin panel. |
0 | 421 |
* |
5 | 422 |
* @since 3.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* @since 4.2.0 The `$style` parameter was deprecated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* @since 4.4.0 The `$role` parameter was deprecated. |
0 | 425 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @param WP_User $user_object The current user object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param string $style Deprecated. Not used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* @param string $role Deprecated. Not used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* @param int $numposts Optional. Post count to display for this user. Defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
* to zero, as in, a new user has made zero posts. |
5 | 431 |
* @return string Output for a single row. |
0 | 432 |
*/ |
5 | 433 |
public function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) { |
434 |
if ( ! ( $user_object instanceof WP_User ) ) { |
|
0 | 435 |
$user_object = get_userdata( (int) $user_object ); |
5 | 436 |
} |
0 | 437 |
$user_object->filter = 'display'; |
9 | 438 |
$email = $user_object->user_email; |
0 | 439 |
|
9 | 440 |
if ( $this->is_site_users ) { |
0 | 441 |
$url = "site-users.php?id={$this->site_id}&"; |
9 | 442 |
} else { |
0 | 443 |
$url = 'users.php?'; |
9 | 444 |
} |
0 | 445 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
$user_roles = $this->get_role_list( $user_object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
|
16 | 448 |
// Set up the hover actions for this user. |
9 | 449 |
$actions = array(); |
450 |
$checkbox = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
$super_admin = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
if ( is_multisite() && current_user_can( 'manage_network_users' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
if ( in_array( $user_object->user_login, get_super_admins(), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
$super_admin = ' — ' . __( 'Super Admin' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
|
16 | 459 |
// Check if the user for this row is editable. |
0 | 460 |
if ( current_user_can( 'list_users' ) ) { |
16 | 461 |
// Set up the user editing link. |
19 | 462 |
$edit_link = esc_url( |
463 |
add_query_arg( |
|
464 |
'wp_http_referer', |
|
465 |
urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), |
|
466 |
get_edit_user_link( $user_object->ID ) |
|
467 |
) |
|
468 |
); |
|
0 | 469 |
|
9 | 470 |
if ( current_user_can( 'edit_user', $user_object->ID ) ) { |
471 |
$edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />"; |
|
0 | 472 |
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
473 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
$edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />"; |
0 | 475 |
} |
476 |
||
19 | 477 |
if ( ! is_multisite() |
478 |
&& get_current_user_id() !== $user_object->ID |
|
479 |
&& current_user_can( 'delete_user', $user_object->ID ) |
|
480 |
) { |
|
9 | 481 |
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>'; |
482 |
} |
|
19 | 483 |
|
484 |
if ( is_multisite() |
|
485 |
&& current_user_can( 'remove_user', $user_object->ID ) |
|
486 |
) { |
|
9 | 487 |
$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>'; |
488 |
} |
|
5 | 489 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
// Add a link to the user's author archive, if not empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
$author_posts_url = get_author_posts_url( $user_object->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
if ( $author_posts_url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
$actions['view'] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
esc_url( $author_posts_url ), |
16 | 496 |
/* translators: %s: Author's display name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
esc_attr( sprintf( __( 'View posts by %s' ), $user_object->display_name ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
__( 'View' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
|
18 | 502 |
// Add a link to send the user a reset password link by email. |
19 | 503 |
if ( get_current_user_id() !== $user_object->ID |
504 |
&& current_user_can( 'edit_user', $user_object->ID ) |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
505 |
&& true === wp_is_password_reset_allowed_for_user( $user_object ) |
19 | 506 |
) { |
18 | 507 |
$actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>'; |
508 |
} |
|
509 |
||
5 | 510 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* Filters the action links displayed under each user in the Users list table. |
5 | 512 |
* |
513 |
* @since 2.8.0 |
|
514 |
* |
|
9 | 515 |
* @param string[] $actions An array of action links to be displayed. |
516 |
* Default 'Edit', 'Delete' for single site, and |
|
517 |
* 'Edit', 'Remove' for Multisite. |
|
518 |
* @param WP_User $user_object WP_User object for the currently listed user. |
|
5 | 519 |
*/ |
0 | 520 |
$actions = apply_filters( 'user_row_actions', $actions, $user_object ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
// Role classes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
$role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) ); |
0 | 524 |
|
16 | 525 |
// Set up the checkbox (because the user is editable, otherwise it's empty). |
526 |
$checkbox = sprintf( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
527 |
'<input type="checkbox" name="users[]" id="user_%1$s" class="%2$s" value="%1$s" />' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
528 |
'<label for="user_%1$s"><span class="screen-reader-text">%3$s</span></label>', |
16 | 529 |
$user_object->ID, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
530 |
$role_classes, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
/* translators: Hidden accessibility text. %s: User login. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
532 |
sprintf( __( 'Select %s' ), $user_object->user_login ) |
16 | 533 |
); |
0 | 534 |
|
535 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
$edit = "<strong>{$user_object->user_login}{$super_admin}</strong>"; |
0 | 537 |
} |
16 | 538 |
|
0 | 539 |
$avatar = get_avatar( $user_object->ID, 32 ); |
540 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
// Comma-separated list of user roles. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
$roles_list = implode( ', ', $user_roles ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
544 |
$row = "<tr id='user-$user_object->ID'>"; |
0 | 545 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
0 | 547 |
|
548 |
foreach ( $columns as $column_name => $column_display_name ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
$classes = "$column_name column-$column_name"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
if ( $primary === $column_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
$classes .= ' has-row-actions column-primary'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
if ( 'posts' === $column_name ) { |
16 | 554 |
$classes .= ' num'; // Special case for that column. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
} |
0 | 556 |
|
16 | 557 |
if ( in_array( $column_name, $hidden, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
$classes .= ' hidden'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
} |
0 | 560 |
|
18 | 561 |
$data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
$attributes = "class='$classes' $data"; |
0 | 564 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
if ( 'cb' === $column_name ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
566 |
$row .= "<th scope='row' class='check-column'>$checkbox</th>"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
568 |
$row .= "<td $attributes>"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
switch ( $column_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
case 'username': |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
571 |
$row .= "$avatar $edit"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
case 'name': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
if ( $user_object->first_name && $user_object->last_name ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
575 |
$row .= sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
576 |
/* translators: 1: User's first name, 2: Last name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
577 |
_x( '%1$s %2$s', 'Display name based on first name and last name' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
578 |
$user_object->first_name, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
579 |
$user_object->last_name |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
580 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
} elseif ( $user_object->first_name ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
$row .= $user_object->first_name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
} elseif ( $user_object->last_name ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
584 |
$row .= $user_object->last_name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
586 |
$row .= sprintf( |
16 | 587 |
'<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
588 |
/* translators: Hidden accessibility text. */ |
16 | 589 |
_x( 'Unknown', 'name' ) |
590 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
case 'email': |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
594 |
$row .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
case 'role': |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
597 |
$row .= esc_html( $roles_list ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
case 'posts': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
if ( $numposts > 0 ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
601 |
$row .= sprintf( |
16 | 602 |
'<a href="%s" class="edit"><span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
603 |
"edit.php?author={$user_object->ID}", |
|
604 |
$numposts, |
|
605 |
sprintf( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
606 |
/* translators: Hidden accessibility text. %s: Number of posts. */ |
16 | 607 |
_n( '%s post by this author', '%s posts by this author', $numposts ), |
608 |
number_format_i18n( $numposts ) |
|
609 |
) |
|
610 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
612 |
$row .= 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* Filters the display output of custom columns in the Users list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* @param string $output Custom column output. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @param string $column_name Column name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* @param int $user_id ID of the currently-listed user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
625 |
$row .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
} |
5 | 627 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
if ( $primary === $column_name ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
629 |
$row .= $this->row_actions( $actions ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
631 |
$row .= '</td>'; |
0 | 632 |
} |
633 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
634 |
$row .= '</tr>'; |
0 | 635 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
636 |
return $row; |
0 | 637 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* Gets the name of the default primary column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
* @return string Name of the default primary column, in this case, 'username'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
protected function get_default_primary_column_name() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
return 'username'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
/** |
19 | 651 |
* Returns an array of translated user role names for a given user object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
* @param WP_User $user_object The WP_User object. |
19 | 656 |
* @return string[] An array of user role names keyed by role. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
protected function get_role_list( $user_object ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
$wp_roles = wp_roles(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
$role_list = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
foreach ( $user_object->roles as $role ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
if ( isset( $wp_roles->role_names[ $role ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
$role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
if ( empty( $role_list ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
$role_list['none'] = _x( 'None', 'no user roles' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
/** |
19 | 674 |
* Filters the returned array of translated role names for a user. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
* |
19 | 678 |
* @param string[] $role_list An array of translated user role names keyed by role. |
9 | 679 |
* @param WP_User $user_object A WP_User object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
return apply_filters( 'get_role_list', $role_list, $user_object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
} |
0 | 683 |
} |