get_editable_roles

Fetch a filtered list of user roles that the current user is allowed to edit.

Description

(array) get_editable_roles(); 

Simple function who's main purpose is to allow filtering of the list of roles in the $wp_roles object so that plugins can remove inappropriate ones depending on the situation or user making edits. Specifically because without filtering anyone with the edit_users capability can edit others to be administrators, even if they are only editors or authors. This filter allows admins to delegate user management.

Returns (array)


Usage

  1. if ( !function_exists( 'get_editable_roles' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/user.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_editable_roles(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/user.php  
  1. function get_editable_roles() { 
  2. $all_roles =wp_roles)->roles; 
  3.  
  4. /** 
  5. * Filters the list of editable roles. 
  6. * @since 2.8.0 
  7. * @param array $all_roles List of roles. 
  8. */ 
  9. $editable_roles = apply_filters( 'editable_roles', $all_roles ); 
  10.  
  11. return $editable_roles;