On this page
wp_roles(): WP_Roles
Retrieves the global WP_Roles instance and instantiates it if necessary.
Return
WP_Roles WP_Roles global instance if not already instantiated.
Source
File: wp-includes/capabilities.php. View all references
function wp_roles() {
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
return $wp_roles;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Roles::__construct() wp-includes/class-wp-roles.php | Constructor. |
Used By
| Used By | Description |
|---|---|
| wp_switch_roles_and_user() wp-includes/ms-blogs.php | Switches the initialized roles and current user capabilities to another site. |
| wp_get_users_with_no_role() wp-includes/user.php | Gets the user IDs of all users with no role on this site. |
| WP_Users_List_Table::get_role_list() wp-admin/includes/class-wp-users-list-table.php | Returns an array of translated user role names for a given user object. |
| edit_user() wp-admin/includes/user.php | Edit user settings based on contents of $_POST |
| get_editable_roles() wp-admin/includes/user.php | Fetch a filtered list of user roles that the current user is allowed to edit. |
| WP_Users_List_Table::get_views() wp-admin/includes/class-wp-users-list-table.php | Return an associative array listing all the views that can be used with this table. |
| WP_User::get_role_caps() wp-includes/class-wp-user.php | Retrieves all of the capabilities of the user’s roles, and merges them with individual user capabilities. |
| WP_Role::add_cap() wp-includes/class-wp-role.php | Assign role a capability. |
| WP_Role::remove_cap() wp-includes/class-wp-role.php | Removes a capability from a role. |
| get_role() wp-includes/capabilities.php | Retrieves role object. |
| add_role() wp-includes/capabilities.php | Adds a role, if it does not exist. |
| remove_role() wp-includes/capabilities.php | Removes a role, if it exists. |
| count_users() wp-includes/user.php | Counts number of users who have each of the user roles. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_roles