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