apply_filters( 'editable_roles', array[] $all_roles )

Filters the list of editable roles.


Parameters Parameters

$all_roles

(array[]) Array of arrays containing role information.


Top ↑

More Information More Information

editable_roles is a filter applied by the function get_editable_roles() to the list of roles that one user can assign to others (a user must have the edit_users capability to change another user’s role). This list is displayed in the bulk operations (if the user has the list_users and promote_users) of the Users Screen, and on the profile screen.


Top ↑

Source Source

File: wp-admin/includes/user.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    Example migrated from Codex:

    Filter out roles with levels higher than the current user’s:

    add_filter('editable_roles', 'remove_higher_levels');
    
    <?php
    function remove_higher_levels($all_roles) {
        $user = wp_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;
    }
    
  2. Skip to note 2 content
    Contributed by stevenlinx

    Example migrated from Codex:

    Add a “No role” option that sets users’ roles to nothing on pages other than the user profile screen (where it already exists):

    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;
    }
    

Top ↑

You must log in before being able to contribute a note or feedback.