This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * Name: Roles and Capabilities |
||
4 | * |
||
5 | * Menu Name: Roles & Capabilities |
||
6 | * |
||
7 | * Description: Create and Manage WordPress User Roles and Capabilities; Uses the '<a |
||
8 | * href="http://wordpress.org/plugins/members/" target="_blank">Members</a>' plugin filters for additional plugin |
||
9 | * integrations; Portions of code based on the '<a href="http://wordpress.org/plugins/members/" |
||
10 | * target="_blank">Members</a>' plugin by Justin Tadlock |
||
11 | * |
||
12 | * Version: 1.0 |
||
13 | * |
||
14 | * Category: Tools |
||
15 | * |
||
16 | * @package Pods\Components |
||
17 | * @subpackage Roles |
||
18 | */ |
||
19 | |||
20 | if ( class_exists( 'Pods_Roles' ) ) { |
||
21 | return; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Class Pods_Roles |
||
26 | */ |
||
27 | class Pods_Roles extends PodsComponent { |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function init() { |
||
33 | |||
34 | add_filter( 'pods_roles_get_capabilities', array( $this, 'remove_deprecated_capabilities' ) ); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Enqueue styles |
||
39 | * |
||
40 | * @since 2.0 |
||
41 | */ |
||
42 | public function admin_assets() { |
||
43 | |||
44 | wp_enqueue_style( 'pods-wizard' ); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Build admin area |
||
49 | * |
||
50 | * @param $options |
||
51 | * @param $component |
||
52 | * |
||
53 | * @return void |
||
54 | * @since 2.0 |
||
55 | */ |
||
56 | public function admin( $options, $component ) { |
||
57 | |||
58 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
59 | |||
60 | // Hook into Gravity Forms roles (since it only adds filter if Members plugin itself is activated |
||
61 | if ( class_exists( 'RGForms' ) && ! has_filter( |
||
62 | 'members_get_capabilities', array( |
||
63 | 'RGForms', |
||
64 | 'members_get_capabilities', |
||
65 | ) |
||
66 | ) ) { |
||
67 | add_filter( 'members_get_capabilities', array( 'RGForms', 'members_get_capabilities' ) ); |
||
68 | } |
||
69 | |||
70 | $default_role = get_option( 'default_role' ); |
||
71 | |||
72 | $roles = array(); |
||
73 | |||
74 | foreach ( $wp_roles->role_objects as $key => $role ) { |
||
75 | $count = $this->count_users( $key ); |
||
76 | |||
77 | $roles[ $key ] = array( |
||
78 | 'id' => $key, |
||
79 | 'label' => $wp_roles->role_names[ $key ], |
||
80 | 'name' => $key, |
||
81 | 'capabilities' => count( (array) $role->capabilities ), |
||
82 | 'users' => sprintf( _n( '%s User', '%s Users', $count, 'pods' ), $count ), |
||
83 | ); |
||
84 | |||
85 | if ( $default_role == $key ) { |
||
86 | $roles[ $key ]['label'] .= ' (site default)'; |
||
87 | } |
||
88 | |||
89 | if ( 0 < $count && pods_is_admin( array( 'list_users' ) ) ) { |
||
90 | $roles[ $key ]['users'] .= '<br /><a href="' . admin_url( esc_url( 'users.php?role=' . $key ) ) . '">' . __( 'View Users', 'pods' ) . '</a>'; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | $ui = array( |
||
0 ignored issues
–
show
|
|||
95 | 'component' => $component, |
||
96 | 'data' => $roles, |
||
97 | 'total' => count( $roles ), |
||
98 | 'total_found' => count( $roles ), |
||
99 | 'items' => 'Roles', |
||
100 | 'item' => 'Role', |
||
101 | 'fields' => array( |
||
102 | 'manage' => array( |
||
103 | 'label' => array( 'label' => __( 'Label', 'pods' ) ), |
||
104 | 'name' => array( 'label' => __( 'Name', 'pods' ) ), |
||
105 | 'capabilities' => array( 'label' => __( 'Capabilities', 'pods' ) ), |
||
106 | 'users' => array( |
||
107 | 'label' => __( 'Users', 'pods' ), |
||
108 | 'type' => 'text', |
||
109 | 'options' => array( |
||
110 | 'text_allow_html' => 1, |
||
111 | 'text_allowed_html_tags' => '', |
||
112 | ), |
||
113 | ), |
||
114 | ), |
||
115 | ), |
||
116 | 'actions_disabled' => array( 'duplicate', 'view', 'export' ), |
||
117 | 'actions_custom' => array( |
||
118 | 'add' => array( $this, 'admin_add' ), |
||
119 | 'edit' => array( $this, 'admin_edit' ), |
||
120 | 'delete' => array( $this, 'admin_delete' ), |
||
121 | ), |
||
122 | 'search' => false, |
||
123 | 'searchable' => false, |
||
124 | 'sortable' => false, |
||
125 | 'pagination' => false, |
||
126 | ); |
||
127 | |||
128 | if ( isset( $roles[ pods_var( 'id', 'get', - 1 ) ] ) ) { |
||
129 | $ui['row'] = $roles[ pods_var( 'id', 'get', - 1 ) ]; |
||
130 | } |
||
131 | |||
132 | if ( ! pods_is_admin( array( 'pods_roles_add' ) ) ) { |
||
133 | $ui['actions_disabled'][] = 'add'; |
||
134 | } |
||
135 | |||
136 | if ( ! pods_is_admin( array( 'pods_roles_edit' ) ) ) { |
||
137 | $ui['actions_disabled'][] = 'edit'; |
||
138 | } |
||
139 | |||
140 | if ( count( $roles ) < 2 || ! pods_is_admin( array( 'pods_roles_delete' ) ) ) { |
||
141 | $ui['actions_disabled'][] = 'delete'; |
||
142 | } |
||
143 | |||
144 | pods_ui( $ui ); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @param $obj |
||
149 | */ |
||
150 | public function admin_add( $obj ) { |
||
151 | |||
152 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
153 | |||
154 | $capabilities = $this->get_capabilities(); |
||
155 | |||
156 | $defaults = $this->get_default_capabilities(); |
||
157 | |||
158 | $component = $obj->x['component']; |
||
159 | |||
160 | $method = 'add'; |
||
161 | // ajax_add |
||
162 | pods_view( PODS_DIR . 'components/Roles/ui/add.php', compact( array_keys( get_defined_vars() ) ) ); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @param $duplicate |
||
167 | * @param $obj |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | public function admin_edit( $duplicate, $obj ) { |
||
172 | |||
173 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
174 | |||
175 | $id = $obj->id; |
||
176 | |||
177 | $capabilities = $this->get_capabilities(); |
||
178 | |||
179 | $role_name = $role_label = $role_capabilities = null; |
||
180 | |||
181 | foreach ( $wp_roles->role_objects as $key => $role ) { |
||
182 | if ( $key != $id ) { |
||
183 | continue; |
||
184 | } |
||
185 | |||
186 | $role_name = $key; |
||
187 | $role_label = $wp_roles->role_names[ $key ]; |
||
188 | $role_capabilities = $role->capabilities; |
||
189 | } |
||
190 | |||
191 | if ( empty( $role ) ) { |
||
192 | return $obj->error( __( 'Role not found, cannot edit it.', 'pods' ) ); |
||
193 | } |
||
194 | |||
195 | $component = $obj->x['component']; |
||
196 | |||
197 | $method = 'edit'; |
||
198 | // ajax_edit |
||
199 | pods_view( PODS_DIR . 'components/Roles/ui/edit.php', compact( array_keys( get_defined_vars() ) ) ); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @param $id |
||
204 | * @param $obj |
||
205 | * |
||
206 | * @return mixed |
||
207 | */ |
||
208 | public function admin_delete( $id, $obj ) { |
||
209 | |||
210 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
211 | |||
212 | $id = $obj->id; |
||
213 | |||
214 | if ( ! isset( $obj->data[ $id ] ) ) { |
||
215 | return $obj->error( __( 'Role not found, it cannot be deleted.', 'pods' ) ); |
||
216 | } |
||
217 | |||
218 | $default_role = get_option( 'default_role' ); |
||
219 | |||
220 | if ( $id == $default_role ) { |
||
221 | return $obj->error( sprintf( __( 'You cannot remove the <strong>%s</strong> role, you must set a new default role for the site first.', 'pods' ), $obj->data[ $id ]['name'] ) ); |
||
222 | } |
||
223 | |||
224 | $wp_user_query = new WP_User_Query( array( 'role' => $id ) ); |
||
225 | |||
226 | $users = $wp_user_query->get_results(); |
||
227 | |||
228 | if ( ! empty( $users ) && is_array( $users ) ) { |
||
229 | foreach ( $users as $user ) { |
||
230 | $user_object = new WP_User( $user ); |
||
231 | |||
232 | if ( $user_object->has_cap( $id ) ) { |
||
233 | $user_object->remove_role( $id ); |
||
234 | $user_object->set_role( $default_role ); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | |||
239 | remove_role( $id ); |
||
240 | |||
241 | $roles = array(); |
||
242 | |||
243 | foreach ( $wp_roles->role_objects as $key => $role ) { |
||
244 | $count = $this->count_users( $key ); |
||
245 | |||
246 | $roles[ $key ] = array( |
||
247 | 'id' => $key, |
||
248 | 'label' => $wp_roles->role_names[ $key ], |
||
249 | 'name' => $key, |
||
250 | 'capabilities' => count( (array) $role->capabilities ), |
||
251 | 'users' => sprintf( _n( '%s User', '%s Users', $count, 'pods' ), $count ), |
||
252 | ); |
||
253 | |||
254 | if ( $default_role == $key ) { |
||
255 | $roles[ $key ]['label'] .= ' (site default)'; |
||
256 | } |
||
257 | |||
258 | if ( 0 < $count && pods_is_admin( array( 'list_users' ) ) ) { |
||
259 | $roles[ $key ]['users'] .= '<br /><a href="' . admin_url( esc_url( 'users.php?role=' . $key ) ) . '">' . __( 'View Users', 'pods' ) . '</a>'; |
||
260 | } |
||
261 | } |
||
262 | |||
263 | $name = $obj->data[ $id ]['label'] . ' (' . $obj->data[ $id ]['name'] . ')'; |
||
264 | |||
265 | $obj->data = $roles; |
||
266 | $obj->total = count( $roles ); |
||
267 | $obj->total_found = count( $roles ); |
||
268 | |||
269 | $obj->message( '<strong>' . $name . '</strong> ' . __( 'role removed from site.', 'pods' ) ); |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * Handle the Add Role AJAX |
||
274 | * |
||
275 | * @param $params |
||
276 | * |
||
277 | * @return mixed|void |
||
278 | */ |
||
279 | public function ajax_add( $params ) { |
||
280 | |||
281 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
282 | |||
283 | $role_name = pods_var_raw( 'role_name', $params ); |
||
284 | $role_label = pods_var_raw( 'role_label', $params ); |
||
285 | |||
286 | $params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() ); |
||
287 | |||
288 | $params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() ); |
||
289 | $params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) ); |
||
290 | |||
291 | $capabilities = array(); |
||
292 | |||
293 | foreach ( $params->capabilities as $capability => $x ) { |
||
294 | if ( empty( $capability ) || true !== (boolean) $x ) { |
||
295 | continue; |
||
296 | } |
||
297 | |||
298 | $capabilities[ esc_attr( $capability ) ] = true; |
||
299 | } |
||
300 | |||
301 | foreach ( $params->custom_capabilities as $x => $capability ) { |
||
302 | if ( empty( $capability ) || '--1' === $x ) { |
||
303 | continue; |
||
304 | } |
||
305 | |||
306 | $capabilities[ esc_attr( $capability ) ] = true; |
||
307 | } |
||
308 | |||
309 | if ( empty( $role_name ) ) { |
||
310 | return pods_error( __( 'Role name is required', 'pods' ) ); |
||
311 | } |
||
312 | |||
313 | if ( empty( $role_label ) ) { |
||
314 | return pods_error( __( 'Role label is required', 'pods' ) ); |
||
315 | } |
||
316 | |||
317 | return add_role( $role_name, $role_label, $capabilities ); |
||
0 ignored issues
–
show
|
|||
318 | } |
||
319 | |||
320 | /** |
||
321 | * Handle the Edit Role AJAX |
||
322 | * |
||
323 | * @todo allow rename role_label |
||
324 | * |
||
325 | * @param $params |
||
326 | * |
||
327 | * @return bool|mixed|void |
||
328 | */ |
||
329 | public function ajax_edit( $params ) { |
||
330 | |||
331 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
332 | |||
333 | $capabilities = $this->get_capabilities(); |
||
334 | |||
335 | $params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() ); |
||
336 | |||
337 | $params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() ); |
||
338 | $params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) ); |
||
339 | |||
340 | if ( ! isset( $params->id ) || empty( $params->id ) || ! isset( $wp_roles->role_objects[ $params->id ] ) ) { |
||
341 | return pods_error( __( 'Role not found, cannot edit it.', 'pods' ) ); |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @var $role WP_Role |
||
346 | */ |
||
347 | $role = $wp_roles->role_objects[ $params->id ]; |
||
348 | $role_name = $params->id; |
||
349 | $role_label = $wp_roles->role_names[ $params->id ]; |
||
350 | $role_capabilities = $role->capabilities; |
||
351 | |||
352 | $new_capabilities = array(); |
||
353 | |||
354 | foreach ( $params->capabilities as $capability => $x ) { |
||
355 | if ( empty( $capability ) || true !== (boolean) $x ) { |
||
356 | continue; |
||
357 | } |
||
358 | |||
359 | $new_capabilities[] = esc_attr( $capability ); |
||
360 | |||
361 | if ( ! $role->has_cap( $capability ) ) { |
||
362 | $role->add_cap( $capability ); |
||
363 | } |
||
364 | } |
||
365 | |||
366 | foreach ( $params->custom_capabilities as $x => $capability ) { |
||
367 | if ( empty( $capability ) ) { |
||
368 | continue; |
||
369 | } |
||
370 | |||
371 | if ( in_array( $capability, $new_capabilities, true ) ) { |
||
372 | continue; |
||
373 | } |
||
374 | |||
375 | $new_capabilities[] = esc_attr( $capability ); |
||
376 | |||
377 | if ( ! $role->has_cap( $capability ) ) { |
||
378 | $role->add_cap( $capability ); |
||
379 | } |
||
380 | } |
||
381 | |||
382 | foreach ( $role_capabilities as $capability => $x ) { |
||
383 | if ( ! in_array( $capability, $new_capabilities, true ) && false === strpos( $capability, 'level_' ) ) { |
||
384 | $role->remove_cap( $capability ); |
||
385 | } |
||
386 | } |
||
387 | |||
388 | return true; |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * Basic logic from Members plugin, it counts users of a specific role |
||
393 | * |
||
394 | * @param $role |
||
395 | * |
||
396 | * @return array |
||
397 | */ |
||
398 | public function count_users( $role ) { |
||
399 | |||
400 | $count_users = count_users(); |
||
401 | |||
402 | $avail_roles = array(); |
||
403 | |||
404 | foreach ( $count_users['avail_roles'] as $count_role => $count ) { |
||
405 | $avail_roles[ $count_role ] = $count; |
||
406 | } |
||
407 | |||
408 | if ( empty( $role ) ) { |
||
409 | return $avail_roles; |
||
410 | } |
||
411 | |||
412 | if ( ! isset( $avail_roles[ $role ] ) ) { |
||
413 | $avail_roles[ $role ] = 0; |
||
414 | } |
||
415 | |||
416 | return $avail_roles[ $role ]; |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * @return array|mixed|void |
||
421 | */ |
||
422 | public function get_capabilities() { |
||
423 | |||
424 | global $wp_roles; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
425 | |||
426 | $default_caps = $this->get_wp_capabilities(); |
||
427 | |||
428 | $role_caps = array(); |
||
429 | |||
430 | foreach ( $wp_roles->role_objects as $key => $role ) { |
||
431 | if ( is_array( $role->capabilities ) ) { |
||
432 | foreach ( $role->capabilities as $cap => $grant ) { |
||
433 | $role_caps[ $cap ] = $cap; |
||
434 | } |
||
435 | } |
||
436 | } |
||
437 | |||
438 | $role_caps = array_unique( $role_caps ); |
||
439 | |||
440 | $plugin_caps = array( |
||
441 | 'pods_roles_add', |
||
442 | 'pods_roles_delete', |
||
443 | 'pods_roles_edit', |
||
444 | ); |
||
445 | |||
446 | $capabilities = array_merge( $default_caps, $role_caps, $plugin_caps ); |
||
447 | |||
448 | // To support Members filters |
||
449 | $capabilities = apply_filters( 'members_get_capabilities', $capabilities ); |
||
450 | |||
451 | $capabilities = apply_filters( 'pods_roles_get_capabilities', $capabilities ); |
||
452 | |||
453 | sort( $capabilities ); |
||
454 | |||
455 | $capabilities = array_unique( $capabilities ); |
||
456 | |||
457 | return $capabilities; |
||
458 | } |
||
459 | |||
460 | /** |
||
461 | * @return array |
||
0 ignored issues
–
show
|
|||
462 | */ |
||
463 | public function get_wp_capabilities() { |
||
464 | |||
465 | $defaults = array( |
||
466 | 'activate_plugins', |
||
467 | 'add_users', |
||
468 | 'create_users', |
||
469 | 'delete_others_pages', |
||
470 | 'delete_others_posts', |
||
471 | 'delete_pages', |
||
472 | 'delete_plugins', |
||
473 | 'delete_posts', |
||
474 | 'delete_private_pages', |
||
475 | 'delete_private_posts', |
||
476 | 'delete_published_pages', |
||
477 | 'delete_published_posts', |
||
478 | 'delete_users', |
||
479 | 'edit_dashboard', |
||
480 | 'edit_files', |
||
481 | 'edit_others_pages', |
||
482 | 'edit_others_posts', |
||
483 | 'edit_pages', |
||
484 | 'edit_plugins', |
||
485 | 'edit_posts', |
||
486 | 'edit_private_pages', |
||
487 | 'edit_private_posts', |
||
488 | 'edit_published_pages', |
||
489 | 'edit_published_posts', |
||
490 | 'edit_theme_options', |
||
491 | 'edit_themes', |
||
492 | 'edit_users', |
||
493 | 'import', |
||
494 | 'install_plugins', |
||
495 | 'install_themes', |
||
496 | 'list_users', |
||
497 | 'manage_categories', |
||
498 | 'manage_links', |
||
499 | 'manage_options', |
||
500 | 'moderate_comments', |
||
501 | 'promote_users', |
||
502 | 'publish_pages', |
||
503 | 'publish_posts', |
||
504 | 'read', |
||
505 | 'read_private_pages', |
||
506 | 'read_private_posts', |
||
507 | 'remove_users', |
||
508 | 'switch_themes', |
||
509 | 'unfiltered_html', |
||
510 | 'unfiltered_upload', |
||
511 | 'update_core', |
||
512 | 'update_plugins', |
||
513 | 'update_themes', |
||
514 | 'upload_files', |
||
515 | ); |
||
516 | |||
517 | return $defaults; |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * @return array|mixed|void |
||
522 | */ |
||
523 | public function get_default_capabilities() { |
||
524 | |||
525 | $capabilities = array( |
||
526 | 'read', |
||
527 | ); |
||
528 | |||
529 | // To support Members filters |
||
530 | $capabilities = apply_filters( 'members_new_role_default_capabilities', $capabilities ); |
||
531 | |||
532 | $capabilities = apply_filters( 'pods_roles_default_capabilities', $capabilities ); |
||
533 | |||
534 | return $capabilities; |
||
535 | } |
||
536 | |||
537 | /** |
||
538 | * @param $capabilities |
||
539 | * |
||
540 | * @return array |
||
541 | */ |
||
542 | public function remove_deprecated_capabilities( $capabilities ) { |
||
543 | |||
544 | $deprecated_capabilities = array( |
||
0 ignored issues
–
show
|
|||
545 | 'level_0', |
||
546 | 'level_1', |
||
547 | 'level_2', |
||
548 | 'level_3', |
||
549 | 'level_4', |
||
550 | 'level_5', |
||
551 | 'level_6', |
||
552 | 'level_7', |
||
553 | 'level_8', |
||
554 | 'level_9', |
||
555 | 'level_10', |
||
556 | ); |
||
557 | |||
558 | $capabilities = array_diff( $capabilities, $deprecated_capabilities ); |
||
559 | |||
560 | return $capabilities; |
||
561 | } |
||
562 | } |
||
563 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.