WP_User::get_role_caps(): bool[]
- Since
- 2.0.0
- Source
wp-includes/class-wp-user.php:508
Retrieves all of the capabilities of the user's roles, and merges them with individual user capabilities.
Description
All of the capabilities of the user's roles are merged with the user's individual capabilities. This means that the user can be denied specific capabilities that their role might have, but the user is specifically denied.
Return
bool[]- Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.
Uses · 5
- is_multisite()Determines whether Multisite is enabled.
- get_current_blog_id()Retrieves the current site ID.
- switch_to_blog()Switches the current blog.
- wp_roles()Retrieves the global WP_Roles instance and instantiates it if necessary.
- restore_current_blog()Restores the current blog, after calling switch_to_blog().
Used by · 8
- WP_User::_init_caps()Sets up capability object properties.
- WP_User::add_cap()Adds capability and grant or deny access to capability.
- WP_User::add_role()Adds role to user.
- WP_User::for_site()Sets the site to operate on. Defaults to the current site.
- WP_User::remove_all_caps()Removes all of the capabilities of the user.
- WP_User::remove_cap()Removes capability from user.
- WP_User::remove_role()Removes role from user.
- WP_User::set_role()Sets the role of the user.
Source
public function get_role_caps() { $switch_site = false; if ( is_multisite() && get_current_blog_id() !== $this->site_id ) { $switch_site = true; switch_to_blog( $this->site_id ); } $wp_roles = wp_roles(); // Filter out caps that are not role names and assign to $this->roles. if ( is_array( $this->caps ) ) { $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); } // Build $allcaps from role caps, overlay user's $caps. $this->allcaps = array(); foreach ( (array) $this->roles as $role ) { $the_role = $wp_roles->get_role( $role ); $this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities ); } $this->allcaps = array_merge( (array) $this->allcaps, (array) $this->caps ); if ( $switch_site ) { restore_current_blog(); } return $this->allcaps; }History
Introduced in 2.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wp-user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.