editable_roles
最后更新于:2021-11-26 09:01:31
apply_filters( ‘editable_roles’, array[] $all_roles )
Filters the list of editable roles.
参数
- $all_roles
-
(array[])
Array of arrays containing role information.
源文件
文件: gc-admin/includes/user.php
add_filter('editable_roles', 'remove_higher_levels'); <?php function remove_higher_levels($all_roles) { $user = gc_get_current_user(); $next_level = 'level_' . ($user->user_level + 1); foreach ( $all_roles as $name => $role ) { if (isset($role['capabilities'][$next_level])) { unset($all_roles[$name]); } } return $all_roles; }
add_filter('editable_roles', 'add_empty_editable_role'); <?php function add_empty_editable_role($all_roles) { $screen = get_current_screen(); if (! (isset($all_roles['']) || 'user-edit' == $screen->id)) { $all_roles[''] = array( 'name' => __('— No role for this site —'), 'capabilities' => array(), ); } return $all_roles; }