author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
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 |
* Core User Role & Capabilities API |
0 | 4 |
* |
5 |
* @package WordPress |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Users |
0 | 7 |
*/ |
8 |
||
9 |
/** |
|
10 |
* Map meta capabilities to primitive capabilities. |
|
11 |
* |
|
12 |
* This does not actually compare whether the user ID has the actual capability, |
|
13 |
* just what the capability or capabilities are. Meta capability list value can |
|
14 |
* be 'delete_user', 'edit_user', 'remove_user', 'promote_user', 'delete_post', |
|
15 |
* 'delete_page', 'edit_post', 'edit_page', 'read_post', or 'read_page'. |
|
16 |
* |
|
17 |
* @since 2.0.0 |
|
18 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @global array $post_type_meta_caps Used to get post type meta capabilities. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @param string $cap Capability name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @param int $user_id User ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @param int $object_id Optional. ID of the specific object to check against if `$cap` is a "meta" cap. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* 'edit_others_posts', etc. The parameter is accessed via func_get_args(). |
0 | 27 |
* @return array Actual capabilities for meta capability. |
28 |
*/ |
|
29 |
function map_meta_cap( $cap, $user_id ) { |
|
30 |
$args = array_slice( func_get_args(), 2 ); |
|
31 |
$caps = array(); |
|
32 |
||
33 |
switch ( $cap ) { |
|
9 | 34 |
case 'remove_user': |
35 |
// In multisite the user must be a super admin to remove themselves. |
|
36 |
if ( isset( $args[0] ) && $user_id == $args[0] && ! is_super_admin( $user_id ) ) { |
|
37 |
$caps[] = 'do_not_allow'; |
|
38 |
} else { |
|
39 |
$caps[] = 'remove_users'; |
|
40 |
} |
|
41 |
break; |
|
42 |
case 'promote_user': |
|
43 |
case 'add_users': |
|
44 |
$caps[] = 'promote_users'; |
|
0 | 45 |
break; |
9 | 46 |
case 'edit_user': |
47 |
case 'edit_users': |
|
48 |
// Allow user to edit itself |
|
49 |
if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) { |
|
50 |
break; |
|
51 |
} |
|
52 |
||
53 |
// In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin. |
|
54 |
if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) { |
|
55 |
$caps[] = 'do_not_allow'; |
|
56 |
} else { |
|
57 |
$caps[] = 'edit_users'; // edit_user maps to edit_users. |
|
58 |
} |
|
59 |
break; |
|
60 |
case 'delete_post': |
|
61 |
case 'delete_page': |
|
62 |
$post = get_post( $args[0] ); |
|
63 |
if ( ! $post ) { |
|
64 |
$caps[] = 'do_not_allow'; |
|
65 |
break; |
|
66 |
} |
|
67 |
||
68 |
if ( 'revision' == $post->post_type ) { |
|
69 |
$post = get_post( $post->post_parent ); |
|
70 |
if ( ! $post ) { |
|
71 |
$caps[] = 'do_not_allow'; |
|
72 |
break; |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
if ( ( get_option( 'page_for_posts' ) == $post->ID ) || ( get_option( 'page_on_front' ) == $post->ID ) ) { |
|
77 |
$caps[] = 'manage_options'; |
|
78 |
break; |
|
79 |
} |
|
0 | 80 |
|
9 | 81 |
$post_type = get_post_type_object( $post->post_type ); |
82 |
if ( ! $post_type ) { |
|
83 |
/* translators: 1: post type, 2: capability name */ |
|
84 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
85 |
$caps[] = 'edit_others_posts'; |
|
86 |
break; |
|
87 |
} |
|
88 |
||
89 |
if ( ! $post_type->map_meta_cap ) { |
|
90 |
$caps[] = $post_type->cap->$cap; |
|
91 |
// Prior to 3.1 we would re-call map_meta_cap here. |
|
92 |
if ( 'delete_post' == $cap ) { |
|
93 |
$cap = $post_type->cap->$cap; |
|
94 |
} |
|
95 |
break; |
|
96 |
} |
|
97 |
||
98 |
// If the post author is set and the user is the author... |
|
99 |
if ( $post->post_author && $user_id == $post->post_author ) { |
|
100 |
// If the post is published or scheduled... |
|
101 |
if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
102 |
$caps[] = $post_type->cap->delete_published_posts; |
|
103 |
} elseif ( 'trash' == $post->post_status ) { |
|
104 |
$status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
105 |
if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
106 |
$caps[] = $post_type->cap->delete_published_posts; |
|
107 |
} else { |
|
108 |
$caps[] = $post_type->cap->delete_posts; |
|
109 |
} |
|
110 |
} else { |
|
111 |
// If the post is draft... |
|
112 |
$caps[] = $post_type->cap->delete_posts; |
|
113 |
} |
|
114 |
} else { |
|
115 |
// The user is trying to edit someone else's post. |
|
116 |
$caps[] = $post_type->cap->delete_others_posts; |
|
117 |
// The post is published or scheduled, extra cap required. |
|
118 |
if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
119 |
$caps[] = $post_type->cap->delete_published_posts; |
|
120 |
} elseif ( 'private' == $post->post_status ) { |
|
121 |
$caps[] = $post_type->cap->delete_private_posts; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
/* |
|
126 |
* Setting the privacy policy page requires `manage_privacy_options`, |
|
127 |
* so deleting it should require that too. |
|
128 |
*/ |
|
129 |
if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) { |
|
130 |
$caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) ); |
|
131 |
} |
|
132 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
break; |
9 | 134 |
// edit_post breaks down to edit_posts, edit_published_posts, or |
135 |
// edit_others_posts |
|
136 |
case 'edit_post': |
|
137 |
case 'edit_page': |
|
138 |
$post = get_post( $args[0] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
$caps[] = 'do_not_allow'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
} |
0 | 143 |
|
9 | 144 |
if ( 'revision' == $post->post_type ) { |
145 |
$post = get_post( $post->post_parent ); |
|
146 |
if ( ! $post ) { |
|
147 |
$caps[] = 'do_not_allow'; |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
$post_type = get_post_type_object( $post->post_type ); |
|
153 |
if ( ! $post_type ) { |
|
154 |
/* translators: 1: post type, 2: capability name */ |
|
155 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
156 |
$caps[] = 'edit_others_posts'; |
|
157 |
break; |
|
158 |
} |
|
0 | 159 |
|
9 | 160 |
if ( ! $post_type->map_meta_cap ) { |
161 |
$caps[] = $post_type->cap->$cap; |
|
162 |
// Prior to 3.1 we would re-call map_meta_cap here. |
|
163 |
if ( 'edit_post' == $cap ) { |
|
164 |
$cap = $post_type->cap->$cap; |
|
165 |
} |
|
166 |
break; |
|
167 |
} |
|
0 | 168 |
|
9 | 169 |
// If the post author is set and the user is the author... |
170 |
if ( $post->post_author && $user_id == $post->post_author ) { |
|
171 |
// If the post is published or scheduled... |
|
172 |
if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
173 |
$caps[] = $post_type->cap->edit_published_posts; |
|
174 |
} elseif ( 'trash' == $post->post_status ) { |
|
175 |
$status = get_post_meta( $post->ID, '_wp_trash_meta_status', true ); |
|
176 |
if ( in_array( $status, array( 'publish', 'future' ), true ) ) { |
|
177 |
$caps[] = $post_type->cap->edit_published_posts; |
|
178 |
} else { |
|
179 |
$caps[] = $post_type->cap->edit_posts; |
|
180 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
} else { |
9 | 182 |
// If the post is draft... |
183 |
$caps[] = $post_type->cap->edit_posts; |
|
5 | 184 |
} |
0 | 185 |
} else { |
9 | 186 |
// The user is trying to edit someone else's post. |
187 |
$caps[] = $post_type->cap->edit_others_posts; |
|
188 |
// The post is published or scheduled, extra cap required. |
|
189 |
if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { |
|
190 |
$caps[] = $post_type->cap->edit_published_posts; |
|
191 |
} elseif ( 'private' == $post->post_status ) { |
|
192 |
$caps[] = $post_type->cap->edit_private_posts; |
|
193 |
} |
|
0 | 194 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
|
9 | 196 |
/* |
197 |
* Setting the privacy policy page requires `manage_privacy_options`, |
|
198 |
* so editing it should require that too. |
|
199 |
*/ |
|
200 |
if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) { |
|
201 |
$caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) ); |
|
202 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
|
0 | 204 |
break; |
9 | 205 |
case 'read_post': |
206 |
case 'read_page': |
|
207 |
$post = get_post( $args[0] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
$caps[] = 'do_not_allow'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
} |
0 | 212 |
|
9 | 213 |
if ( 'revision' == $post->post_type ) { |
214 |
$post = get_post( $post->post_parent ); |
|
215 |
if ( ! $post ) { |
|
216 |
$caps[] = 'do_not_allow'; |
|
217 |
break; |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
$post_type = get_post_type_object( $post->post_type ); |
|
222 |
if ( ! $post_type ) { |
|
223 |
/* translators: 1: post type, 2: capability name */ |
|
224 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
225 |
$caps[] = 'edit_others_posts'; |
|
226 |
break; |
|
227 |
} |
|
0 | 228 |
|
9 | 229 |
if ( ! $post_type->map_meta_cap ) { |
230 |
$caps[] = $post_type->cap->$cap; |
|
231 |
// Prior to 3.1 we would re-call map_meta_cap here. |
|
232 |
if ( 'read_post' == $cap ) { |
|
233 |
$cap = $post_type->cap->$cap; |
|
234 |
} |
|
235 |
break; |
|
236 |
} |
|
0 | 237 |
|
9 | 238 |
$status_obj = get_post_status_object( $post->post_status ); |
239 |
if ( $status_obj->public ) { |
|
240 |
$caps[] = $post_type->cap->read; |
|
241 |
break; |
|
242 |
} |
|
243 |
||
244 |
if ( $post->post_author && $user_id == $post->post_author ) { |
|
245 |
$caps[] = $post_type->cap->read; |
|
246 |
} elseif ( $status_obj->private ) { |
|
247 |
$caps[] = $post_type->cap->read_private_posts; |
|
0 | 248 |
} else { |
9 | 249 |
$caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
5 | 250 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
break; |
9 | 252 |
case 'publish_post': |
253 |
$post = get_post( $args[0] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
$caps[] = 'do_not_allow'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
} |
0 | 258 |
|
9 | 259 |
$post_type = get_post_type_object( $post->post_type ); |
260 |
if ( ! $post_type ) { |
|
261 |
/* translators: 1: post type, 2: capability name */ |
|
262 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.' ), $post->post_type, $cap ), '4.4.0' ); |
|
263 |
$caps[] = 'edit_others_posts'; |
|
264 |
break; |
|
265 |
} |
|
0 | 266 |
|
9 | 267 |
$caps[] = $post_type->cap->publish_posts; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
break; |
9 | 269 |
case 'edit_post_meta': |
270 |
case 'delete_post_meta': |
|
271 |
case 'add_post_meta': |
|
272 |
case 'edit_comment_meta': |
|
273 |
case 'delete_comment_meta': |
|
274 |
case 'add_comment_meta': |
|
275 |
case 'edit_term_meta': |
|
276 |
case 'delete_term_meta': |
|
277 |
case 'add_term_meta': |
|
278 |
case 'edit_user_meta': |
|
279 |
case 'delete_user_meta': |
|
280 |
case 'add_user_meta': |
|
281 |
list( $_, $object_type, $_ ) = explode( '_', $cap ); |
|
282 |
$object_id = (int) $args[0]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
|
9 | 284 |
$object_subtype = get_object_subtype( $object_type, $object_id ); |
0 | 285 |
|
9 | 286 |
if ( empty( $object_subtype ) ) { |
287 |
$caps[] = 'do_not_allow'; |
|
288 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
|
9 | 291 |
$caps = map_meta_cap( "edit_{$object_type}", $user_id, $object_id ); |
292 |
||
293 |
$meta_key = isset( $args[1] ) ? $args[1] : false; |
|
294 |
||
295 |
if ( $meta_key ) { |
|
296 |
$allowed = ! is_protected_meta( $meta_key, $object_type ); |
|
297 |
||
298 |
if ( ! empty( $object_subtype ) && has_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}" ) ) { |
|
299 |
||
300 |
/** |
|
301 |
* Filters whether the user is allowed to edit a specific meta key of a specific object type and subtype. |
|
302 |
* |
|
303 |
* The dynamic portions of the hook name, `$object_type`, `$meta_key`, |
|
304 |
* and `$object_subtype`, refer to the metadata object type (comment, post, term or user), |
|
305 |
* the meta key value, and the object subtype respectively. |
|
306 |
* |
|
307 |
* @since 4.9.8 |
|
308 |
* |
|
309 |
* @param bool $allowed Whether the user can add the object meta. Default false. |
|
310 |
* @param string $meta_key The meta key. |
|
311 |
* @param int $object_id Object ID. |
|
312 |
* @param int $user_id User ID. |
|
313 |
* @param string $cap Capability name. |
|
314 |
* @param string[] $caps Array of the user's capabilities. |
|
315 |
*/ |
|
316 |
$allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps ); |
|
317 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
|
9 | 319 |
/** |
320 |
* Filters whether the user is allowed to edit a specific meta key of a specific object type. |
|
321 |
* |
|
322 |
* Return true to have the mapped meta caps from `edit_{$object_type}` apply. |
|
323 |
* |
|
324 |
* The dynamic portion of the hook name, `$object_type` refers to the object type being filtered. |
|
325 |
* The dynamic portion of the hook name, `$meta_key`, refers to the meta key passed to map_meta_cap(). |
|
326 |
* |
|
327 |
* @since 3.3.0 As `auth_post_meta_{$meta_key}`. |
|
328 |
* @since 4.6.0 |
|
329 |
* |
|
330 |
* @param bool $allowed Whether the user can add the object meta. Default false. |
|
331 |
* @param string $meta_key The meta key. |
|
332 |
* @param int $object_id Object ID. |
|
333 |
* @param int $user_id User ID. |
|
334 |
* @param string $cap Capability name. |
|
335 |
* @param string[] $caps Array of the user's capabilities. |
|
336 |
*/ |
|
337 |
$allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps ); |
|
338 |
} |
|
339 |
||
340 |
if ( ! empty( $object_subtype ) ) { |
|
341 |
||
342 |
/** |
|
343 |
* Filters whether the user is allowed to edit meta for specific object types/subtypes. |
|
344 |
* |
|
345 |
* Return true to have the mapped meta caps from `edit_{$object_type}` apply. |
|
346 |
* |
|
347 |
* The dynamic portion of the hook name, `$object_type` refers to the object type being filtered. |
|
348 |
* The dynamic portion of the hook name, `$object_subtype` refers to the object subtype being filtered. |
|
349 |
* The dynamic portion of the hook name, `$meta_key`, refers to the meta key passed to map_meta_cap(). |
|
350 |
* |
|
351 |
* @since 4.6.0 As `auth_post_{$post_type}_meta_{$meta_key}`. |
|
352 |
* @since 4.7.0 |
|
353 |
* @deprecated 4.9.8 Use `auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}` |
|
354 |
* |
|
355 |
* @param bool $allowed Whether the user can add the object meta. Default false. |
|
356 |
* @param string $meta_key The meta key. |
|
357 |
* @param int $object_id Object ID. |
|
358 |
* @param int $user_id User ID. |
|
359 |
* @param string $cap Capability name. |
|
360 |
* @param string[] $caps Array of the user's capabilities. |
|
361 |
*/ |
|
362 |
$allowed = apply_filters_deprecated( "auth_{$object_type}_{$object_subtype}_meta_{$meta_key}", array( $allowed, $meta_key, $object_id, $user_id, $cap, $caps ), '4.9.8', "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}" ); |
|
363 |
} |
|
364 |
||
365 |
if ( ! $allowed ) { |
|
366 |
$caps[] = $cap; |
|
367 |
} |
|
368 |
} |
|
369 |
break; |
|
370 |
case 'edit_comment': |
|
371 |
$comment = get_comment( $args[0] ); |
|
372 |
if ( ! $comment ) { |
|
373 |
$caps[] = 'do_not_allow'; |
|
374 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
|
9 | 377 |
$post = get_post( $comment->comment_post_ID ); |
378 |
||
379 |
/* |
|
380 |
* If the post doesn't exist, we have an orphaned comment. |
|
381 |
* Fall back to the edit_posts capability, instead. |
|
382 |
*/ |
|
383 |
if ( $post ) { |
|
384 |
$caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
385 |
} else { |
|
386 |
$caps = map_meta_cap( 'edit_posts', $user_id ); |
|
387 |
} |
|
388 |
break; |
|
389 |
case 'unfiltered_upload': |
|
390 |
if ( defined( 'ALLOW_UNFILTERED_UPLOADS' ) && ALLOW_UNFILTERED_UPLOADS && ( ! is_multisite() || is_super_admin( $user_id ) ) ) { |
|
391 |
$caps[] = $cap; |
|
392 |
} else { |
|
393 |
$caps[] = 'do_not_allow'; |
|
394 |
} |
|
395 |
break; |
|
396 |
case 'edit_css': |
|
397 |
case 'unfiltered_html': |
|
398 |
// Disallow unfiltered_html for all users, even admins and super admins. |
|
399 |
if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) { |
|
400 |
$caps[] = 'do_not_allow'; |
|
401 |
} elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
402 |
$caps[] = 'do_not_allow'; |
|
403 |
} else { |
|
404 |
$caps[] = 'unfiltered_html'; |
|
405 |
} |
|
406 |
break; |
|
407 |
case 'edit_files': |
|
408 |
case 'edit_plugins': |
|
409 |
case 'edit_themes': |
|
410 |
// Disallow the file editors. |
|
411 |
if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) { |
|
412 |
$caps[] = 'do_not_allow'; |
|
413 |
} elseif ( ! wp_is_file_mod_allowed( 'capability_edit_themes' ) ) { |
|
414 |
$caps[] = 'do_not_allow'; |
|
415 |
} elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
416 |
$caps[] = 'do_not_allow'; |
|
417 |
} else { |
|
0 | 418 |
$caps[] = $cap; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
} |
9 | 420 |
break; |
421 |
case 'update_plugins': |
|
422 |
case 'delete_plugins': |
|
423 |
case 'install_plugins': |
|
424 |
case 'upload_plugins': |
|
425 |
case 'update_themes': |
|
426 |
case 'delete_themes': |
|
427 |
case 'install_themes': |
|
428 |
case 'upload_themes': |
|
429 |
case 'update_core': |
|
430 |
// Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
|
431 |
// Files in uploads are excepted. |
|
432 |
if ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) { |
|
433 |
$caps[] = 'do_not_allow'; |
|
434 |
} elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
435 |
$caps[] = 'do_not_allow'; |
|
436 |
} elseif ( 'upload_themes' === $cap ) { |
|
437 |
$caps[] = 'install_themes'; |
|
438 |
} elseif ( 'upload_plugins' === $cap ) { |
|
439 |
$caps[] = 'install_plugins'; |
|
440 |
} else { |
|
441 |
$caps[] = $cap; |
|
442 |
} |
|
443 |
break; |
|
444 |
case 'install_languages': |
|
445 |
case 'update_languages': |
|
446 |
if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) { |
|
447 |
$caps[] = 'do_not_allow'; |
|
448 |
} elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
449 |
$caps[] = 'do_not_allow'; |
|
450 |
} else { |
|
451 |
$caps[] = 'install_languages'; |
|
452 |
} |
|
453 |
break; |
|
454 |
case 'activate_plugins': |
|
455 |
case 'deactivate_plugins': |
|
456 |
case 'activate_plugin': |
|
457 |
case 'deactivate_plugin': |
|
458 |
$caps[] = 'activate_plugins'; |
|
459 |
if ( is_multisite() ) { |
|
460 |
// update_, install_, and delete_ are handled above with is_super_admin(). |
|
461 |
$menu_perms = get_site_option( 'menu_items', array() ); |
|
462 |
if ( empty( $menu_perms['plugins'] ) ) { |
|
463 |
$caps[] = 'manage_network_plugins'; |
|
464 |
} |
|
465 |
} |
|
0 | 466 |
break; |
9 | 467 |
case 'resume_plugin': |
468 |
$caps[] = 'resume_plugins'; |
|
469 |
break; |
|
470 |
case 'resume_theme': |
|
471 |
$caps[] = 'resume_themes'; |
|
472 |
break; |
|
473 |
case 'delete_user': |
|
474 |
case 'delete_users': |
|
475 |
// If multisite only super admins can delete users. |
|
476 |
if ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
477 |
$caps[] = 'do_not_allow'; |
|
478 |
} else { |
|
479 |
$caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
480 |
} |
|
481 |
break; |
|
482 |
case 'create_users': |
|
483 |
if ( ! is_multisite() ) { |
|
484 |
$caps[] = $cap; |
|
485 |
} elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) { |
|
486 |
$caps[] = $cap; |
|
487 |
} else { |
|
488 |
$caps[] = 'do_not_allow'; |
|
489 |
} |
|
490 |
break; |
|
491 |
case 'manage_links': |
|
492 |
if ( get_option( 'link_manager_enabled' ) ) { |
|
493 |
$caps[] = $cap; |
|
494 |
} else { |
|
495 |
$caps[] = 'do_not_allow'; |
|
496 |
} |
|
497 |
break; |
|
498 |
case 'customize': |
|
499 |
$caps[] = 'edit_theme_options'; |
|
500 |
break; |
|
501 |
case 'delete_site': |
|
502 |
if ( is_multisite() ) { |
|
503 |
$caps[] = 'manage_options'; |
|
504 |
} else { |
|
505 |
$caps[] = 'do_not_allow'; |
|
506 |
} |
|
507 |
break; |
|
508 |
case 'edit_term': |
|
509 |
case 'delete_term': |
|
510 |
case 'assign_term': |
|
511 |
$term_id = (int) $args[0]; |
|
512 |
$term = get_term( $term_id ); |
|
513 |
if ( ! $term || is_wp_error( $term ) ) { |
|
514 |
$caps[] = 'do_not_allow'; |
|
515 |
break; |
|
516 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
|
9 | 518 |
$tax = get_taxonomy( $term->taxonomy ); |
519 |
if ( ! $tax ) { |
|
520 |
$caps[] = 'do_not_allow'; |
|
521 |
break; |
|
522 |
} |
|
523 |
||
524 |
if ( 'delete_term' === $cap && ( $term->term_id == get_option( 'default_' . $term->taxonomy ) ) ) { |
|
525 |
$caps[] = 'do_not_allow'; |
|
526 |
break; |
|
527 |
} |
|
528 |
||
529 |
$taxo_cap = $cap . 's'; |
|
530 |
||
531 |
$caps = map_meta_cap( $tax->cap->$taxo_cap, $user_id, $term_id ); |
|
532 |
||
533 |
break; |
|
534 |
case 'manage_post_tags': |
|
535 |
case 'edit_categories': |
|
536 |
case 'edit_post_tags': |
|
537 |
case 'delete_categories': |
|
538 |
case 'delete_post_tags': |
|
539 |
$caps[] = 'manage_categories'; |
|
540 |
break; |
|
541 |
case 'assign_categories': |
|
542 |
case 'assign_post_tags': |
|
543 |
$caps[] = 'edit_posts'; |
|
544 |
break; |
|
545 |
case 'create_sites': |
|
546 |
case 'delete_sites': |
|
547 |
case 'manage_network': |
|
548 |
case 'manage_sites': |
|
549 |
case 'manage_network_users': |
|
550 |
case 'manage_network_plugins': |
|
551 |
case 'manage_network_themes': |
|
552 |
case 'manage_network_options': |
|
553 |
case 'upgrade_network': |
|
0 | 554 |
$caps[] = $cap; |
9 | 555 |
break; |
556 |
case 'setup_network': |
|
557 |
if ( is_multisite() ) { |
|
558 |
$caps[] = 'manage_network_options'; |
|
559 |
} else { |
|
560 |
$caps[] = 'manage_options'; |
|
561 |
} |
|
562 |
break; |
|
563 |
case 'update_php': |
|
564 |
if ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
565 |
$caps[] = 'do_not_allow'; |
|
566 |
} else { |
|
567 |
$caps[] = 'update_core'; |
|
568 |
} |
|
569 |
break; |
|
570 |
case 'export_others_personal_data': |
|
571 |
case 'erase_others_personal_data': |
|
572 |
case 'manage_privacy_options': |
|
573 |
$caps[] = is_multisite() ? 'manage_network' : 'manage_options'; |
|
574 |
break; |
|
575 |
default: |
|
576 |
// Handle meta capabilities for custom post types. |
|
577 |
global $post_type_meta_caps; |
|
578 |
if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
579 |
$args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
580 |
return call_user_func_array( 'map_meta_cap', $args ); |
|
581 |
} |
|
582 |
||
583 |
// Block capabilities map to their post equivalent. |
|
584 |
$block_caps = array( |
|
585 |
'edit_blocks', |
|
586 |
'edit_others_blocks', |
|
587 |
'publish_blocks', |
|
588 |
'read_private_blocks', |
|
589 |
'delete_blocks', |
|
590 |
'delete_private_blocks', |
|
591 |
'delete_published_blocks', |
|
592 |
'delete_others_blocks', |
|
593 |
'edit_private_blocks', |
|
594 |
'edit_published_blocks', |
|
595 |
); |
|
596 |
if ( in_array( $cap, $block_caps, true ) ) { |
|
597 |
$cap = str_replace( '_blocks', '_posts', $cap ); |
|
598 |
} |
|
599 |
||
600 |
// If no meta caps match, return the original cap. |
|
0 | 601 |
$caps[] = $cap; |
602 |
} |
|
603 |
||
5 | 604 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* Filters a user's capabilities depending on specific context and/or privilege. |
5 | 606 |
* |
607 |
* @since 2.8.0 |
|
608 |
* |
|
9 | 609 |
* @param string[] $caps Array of the user's capabilities. |
610 |
* @param string $cap Capability name. |
|
611 |
* @param int $user_id The user ID. |
|
612 |
* @param array $args Adds the context to the cap. Typically the object ID. |
|
5 | 613 |
*/ |
614 |
return apply_filters( 'map_meta_cap', $caps, $cap, $user_id, $args ); |
|
0 | 615 |
} |
616 |
||
617 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* Whether the current user has a specific capability. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* While checking against particular roles in place of a capability is supported |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* in part, this practice is discouraged as it may produce unreliable results. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* Note: Will always return true if the current user is a super admin, unless specifically denied. |
0 | 624 |
* |
625 |
* @since 2.0.0 |
|
626 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* @see WP_User::has_cap() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* @see map_meta_cap() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* @param string $capability Capability name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* @param int $object_id Optional. ID of the specific object to check against if `$capability` is a "meta" cap. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* "Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* 'edit_others_posts', etc. Accessed via func_get_args() and passed to WP_User::has_cap(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* then map_meta_cap(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* passed, whether the current user has the given meta capability for the given object. |
0 | 638 |
*/ |
639 |
function current_user_can( $capability ) { |
|
640 |
$current_user = wp_get_current_user(); |
|
641 |
||
9 | 642 |
if ( empty( $current_user ) ) { |
0 | 643 |
return false; |
9 | 644 |
} |
0 | 645 |
|
646 |
$args = array_slice( func_get_args(), 1 ); |
|
647 |
$args = array_merge( array( $capability ), $args ); |
|
648 |
||
649 |
return call_user_func_array( array( $current_user, 'has_cap' ), $args ); |
|
650 |
} |
|
651 |
||
652 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
* Whether the current user has a specific capability for a given site. |
0 | 654 |
* |
655 |
* @since 3.0.0 |
|
656 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
* @param int $blog_id Site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
* @param string $capability Capability name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
* @return bool Whether the user has the given capability. |
0 | 660 |
*/ |
661 |
function current_user_can_for_blog( $blog_id, $capability ) { |
|
5 | 662 |
$switched = is_multisite() ? switch_to_blog( $blog_id ) : false; |
0 | 663 |
|
664 |
$current_user = wp_get_current_user(); |
|
665 |
||
5 | 666 |
if ( empty( $current_user ) ) { |
667 |
if ( $switched ) { |
|
668 |
restore_current_blog(); |
|
669 |
} |
|
0 | 670 |
return false; |
5 | 671 |
} |
0 | 672 |
|
673 |
$args = array_slice( func_get_args(), 2 ); |
|
674 |
$args = array_merge( array( $capability ), $args ); |
|
675 |
||
676 |
$can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); |
|
677 |
||
5 | 678 |
if ( $switched ) { |
0 | 679 |
restore_current_blog(); |
5 | 680 |
} |
0 | 681 |
|
682 |
return $can; |
|
683 |
} |
|
684 |
||
685 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
* Whether the author of the supplied post has a specific capability. |
0 | 687 |
* |
688 |
* @since 2.9.0 |
|
689 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* @param int|WP_Post $post Post ID or post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* @param string $capability Capability name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
* @return bool Whether the post author has the given capability. |
0 | 693 |
*/ |
694 |
function author_can( $post, $capability ) { |
|
9 | 695 |
if ( ! $post = get_post( $post ) ) { |
0 | 696 |
return false; |
9 | 697 |
} |
0 | 698 |
|
699 |
$author = get_userdata( $post->post_author ); |
|
700 |
||
9 | 701 |
if ( ! $author ) { |
0 | 702 |
return false; |
9 | 703 |
} |
0 | 704 |
|
705 |
$args = array_slice( func_get_args(), 2 ); |
|
706 |
$args = array_merge( array( $capability ), $args ); |
|
707 |
||
708 |
return call_user_func_array( array( $author, 'has_cap' ), $args ); |
|
709 |
} |
|
710 |
||
711 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
* Whether a particular user has a specific capability. |
0 | 713 |
* |
714 |
* @since 3.1.0 |
|
715 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
* @param int|WP_User $user User ID or object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* @param string $capability Capability name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
* @return bool Whether the user has the given capability. |
0 | 719 |
*/ |
720 |
function user_can( $user, $capability ) { |
|
9 | 721 |
if ( ! is_object( $user ) ) { |
0 | 722 |
$user = get_userdata( $user ); |
9 | 723 |
} |
0 | 724 |
|
9 | 725 |
if ( ! $user || ! $user->exists() ) { |
0 | 726 |
return false; |
9 | 727 |
} |
0 | 728 |
|
729 |
$args = array_slice( func_get_args(), 2 ); |
|
730 |
$args = array_merge( array( $capability ), $args ); |
|
731 |
||
732 |
return call_user_func_array( array( $user, 'has_cap' ), $args ); |
|
733 |
} |
|
734 |
||
735 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
* Retrieves the global WP_Roles instance and instantiates it if necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
* @global WP_Roles $wp_roles WP_Roles global instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
* @return WP_Roles WP_Roles global instance if not already instantiated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
function wp_roles() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
global $wp_roles; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
if ( ! isset( $wp_roles ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
$wp_roles = new WP_Roles(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
return $wp_roles; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
/** |
0 | 754 |
* Retrieve role object. |
755 |
* |
|
756 |
* @since 2.0.0 |
|
757 |
* |
|
758 |
* @param string $role Role name. |
|
759 |
* @return WP_Role|null WP_Role object if found, null if the role does not exist. |
|
760 |
*/ |
|
761 |
function get_role( $role ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
return wp_roles()->get_role( $role ); |
0 | 763 |
} |
764 |
||
765 |
/** |
|
766 |
* Add role, if it does not exist. |
|
767 |
* |
|
768 |
* @since 2.0.0 |
|
769 |
* |
|
770 |
* @param string $role Role name. |
|
771 |
* @param string $display_name Display name for role. |
|
772 |
* @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false ); |
|
773 |
* @return WP_Role|null WP_Role object if role is added, null if already exists. |
|
774 |
*/ |
|
775 |
function add_role( $role, $display_name, $capabilities = array() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
if ( empty( $role ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
return wp_roles()->add_role( $role, $display_name, $capabilities ); |
0 | 780 |
} |
781 |
||
782 |
/** |
|
783 |
* Remove role, if it exists. |
|
784 |
* |
|
785 |
* @since 2.0.0 |
|
786 |
* |
|
787 |
* @param string $role Role name. |
|
788 |
*/ |
|
789 |
function remove_role( $role ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
wp_roles()->remove_role( $role ); |
0 | 791 |
} |
792 |
||
793 |
/** |
|
794 |
* Retrieve a list of super admins. |
|
795 |
* |
|
796 |
* @since 3.0.0 |
|
797 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
* @global array $super_admins |
0 | 799 |
* |
800 |
* @return array List of super admin logins |
|
801 |
*/ |
|
802 |
function get_super_admins() { |
|
803 |
global $super_admins; |
|
804 |
||
9 | 805 |
if ( isset( $super_admins ) ) { |
0 | 806 |
return $super_admins; |
9 | 807 |
} else { |
808 |
return get_site_option( 'site_admins', array( 'admin' ) ); |
|
809 |
} |
|
0 | 810 |
} |
811 |
||
812 |
/** |
|
813 |
* Determine if user is a site admin. |
|
814 |
* |
|
815 |
* @since 3.0.0 |
|
816 |
* |
|
817 |
* @param int $user_id (Optional) The ID of a user. Defaults to the current user. |
|
818 |
* @return bool True if the user is a site admin. |
|
819 |
*/ |
|
820 |
function is_super_admin( $user_id = false ) { |
|
9 | 821 |
if ( ! $user_id || $user_id == get_current_user_id() ) { |
0 | 822 |
$user = wp_get_current_user(); |
9 | 823 |
} else { |
0 | 824 |
$user = get_userdata( $user_id ); |
9 | 825 |
} |
0 | 826 |
|
9 | 827 |
if ( ! $user || ! $user->exists() ) { |
0 | 828 |
return false; |
9 | 829 |
} |
0 | 830 |
|
831 |
if ( is_multisite() ) { |
|
832 |
$super_admins = get_super_admins(); |
|
9 | 833 |
if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) { |
0 | 834 |
return true; |
9 | 835 |
} |
0 | 836 |
} else { |
9 | 837 |
if ( $user->has_cap( 'delete_users' ) ) { |
0 | 838 |
return true; |
9 | 839 |
} |
0 | 840 |
} |
841 |
||
842 |
return false; |
|
843 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
* Grants Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
* @global array $super_admins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
* @param int $user_id ID of the user to be granted Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
* @return bool True on success, false on failure. This can fail when the user is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
* already a super admin or when the `$super_admins` global is defined. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
function grant_super_admin( $user_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
// If global super_admins override is defined, there is nothing to do here. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* Fires before the user is granted Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
* @param int $user_id ID of the user that is about to be granted Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
do_action( 'grant_super_admin', $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
// Directly fetch site_admins instead of using get_super_admins() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$super_admins = get_site_option( 'site_admins', array( 'admin' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
$user = get_userdata( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
if ( $user && ! in_array( $user->user_login, $super_admins ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
$super_admins[] = $user->user_login; |
9 | 877 |
update_site_option( 'site_admins', $super_admins ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
* Fires after the user is granted Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
* @param int $user_id ID of the user that was granted Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
do_action( 'granted_super_admin', $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
* Revokes Super Admin privileges. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
* @global array $super_admins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* @param int $user_id ID of the user Super Admin privileges to be revoked from. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* @return bool True on success, false on failure. This can fail when the user's email |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
* is the network admin email or when the `$super_admins` global is defined. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
function revoke_super_admin( $user_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
// If global super_admins override is defined, there is nothing to do here. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
* Fires before the user's Super Admin privileges are revoked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
* @param int $user_id ID of the user Super Admin privileges are being revoked from. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
do_action( 'revoke_super_admin', $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
// Directly fetch site_admins instead of using get_super_admins() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
$super_admins = get_site_option( 'site_admins', array( 'admin' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
$user = get_userdata( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) { |
9 | 924 |
unset( $super_admins[ $key ] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
update_site_option( 'site_admins', $super_admins ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
* Fires after the user's Super Admin privileges are revoked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
* @param int $user_id ID of the user Super Admin privileges were revoked from. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
do_action( 'revoked_super_admin', $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
* Filters the user capabilities to grant the 'install_languages' capability as necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
* A user must have at least one out of the 'update_core', 'install_plugins', and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
* 'install_themes' capabilities to qualify for 'install_languages'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
* |
9 | 949 |
* @param bool[] $allcaps An array of all the user's capabilities. |
950 |
* @return bool[] Filtered array of the user's capabilities. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
function wp_maybe_grant_install_languages_cap( $allcaps ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
if ( ! empty( $allcaps['update_core'] ) || ! empty( $allcaps['install_plugins'] ) || ! empty( $allcaps['install_themes'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
$allcaps['install_languages'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
return $allcaps; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
} |
9 | 959 |
|
960 |
/** |
|
961 |
* Filters the user capabilities to grant the 'resume_plugins' and 'resume_themes' capabilities as necessary. |
|
962 |
* |
|
963 |
* @since 5.2.0 |
|
964 |
* |
|
965 |
* @param bool[] $allcaps An array of all the user's capabilities. |
|
966 |
* @return bool[] Filtered array of the user's capabilities. |
|
967 |
*/ |
|
968 |
function wp_maybe_grant_resume_extensions_caps( $allcaps ) { |
|
969 |
// Even in a multisite, regular administrators should be able to resume plugins. |
|
970 |
if ( ! empty( $allcaps['activate_plugins'] ) ) { |
|
971 |
$allcaps['resume_plugins'] = true; |
|
972 |
} |
|
973 |
||
974 |
// Even in a multisite, regular administrators should be able to resume themes. |
|
975 |
if ( ! empty( $allcaps['switch_themes'] ) ) { |
|
976 |
$allcaps['resume_themes'] = true; |
|
977 |
} |
|
978 |
||
979 |
return $allcaps; |
|
980 |
} |
|
981 |
||
982 |
/** |
|
983 |
* Filters the user capabilities to grant the 'view_site_health_checks' capabilities as necessary. |
|
984 |
* |
|
985 |
* @since 5.2.2 |
|
986 |
* |
|
987 |
* @param bool[] $allcaps An array of all the user's capabilities. |
|
988 |
* @param string[] $caps Required primitive capabilities for the requested capability. |
|
989 |
* @param array $args { |
|
990 |
* Arguments that accompany the requested capability check. |
|
991 |
* |
|
992 |
* @type string $0 Requested capability. |
|
993 |
* @type int $1 Concerned user ID. |
|
994 |
* @type mixed ...$2 Optional second and further parameters, typically object ID. |
|
995 |
* } |
|
996 |
* @param WP_User $user The user object. |
|
997 |
* @return bool[] Filtered array of the user's capabilities. |
|
998 |
*/ |
|
999 |
function wp_maybe_grant_site_health_caps( $allcaps, $caps, $args, $user ) { |
|
1000 |
if ( ! empty( $allcaps['install_plugins'] ) && ( ! is_multisite() || is_super_admin( $user->ID ) ) ) { |
|
1001 |
$allcaps['view_site_health_checks'] = true; |
|
1002 |
} |
|
1003 |
||
1004 |
return $allcaps; |
|
1005 |
} |
|
1006 |
||
1007 |
return; |
|
1008 |
||
1009 |
// Dummy gettext calls to get strings in the catalog. |
|
1010 |
/* translators: user role for administrators */ |
|
1011 |
_x( 'Administrator', 'User role' ); |
|
1012 |
/* translators: user role for editors */ |
|
1013 |
_x( 'Editor', 'User role' ); |
|
1014 |
/* translators: user role for authors */ |
|
1015 |
_x( 'Author', 'User role' ); |
|
1016 |
/* translators: user role for contributors */ |
|
1017 |
_x( 'Contributor', 'User role' ); |
|
1018 |
/* translators: user role for subscriber */ |
|
1019 |
_x( 'Subscriber', 'User role' ); |