/** * Retrieve all of the role capabilities and merge with individual capabilities. * * All of the capabilities of the roles the user belongs to are merged with * the users individual roles. This also means that the user can be denied * specific roles that their role might have, but the specific user isn't * granted permission to. * * @since 4.8.0 * @access public * * @return array List of all capabilities for the user. */ public function get_role_caps() { $this->allcaps = parent::get_role_caps(); //TODO: There is a bug in Core in this function, and it is explicitly a bug here either. // For discussion about a fix, see https://core.trac.wordpress.org/ticket/36961 // The fix here will happen after the fix is in place in Core. $wp_global_roles = wp_global_roles(); //Filter out caps that are not role names and assign to $this->global_roles if (is_array($this->global_caps)) { $this->global_roles = array_filter(array_keys($this->global_caps), array($wp_global_roles, 'is_role')); } //Build $allcaps from role caps, overlay user's $caps $this->allcaps = array(); foreach ((array) $this->global_roles as $role) { $the_role = $wp_global_roles->get_role($role); $this->allcaps = array_merge((array) $this->allcaps, (array) $the_role->capabilities); } $this->allcaps = array_merge((array) $this->allcaps, (array) $this->global_caps); return $this->allcaps; }
/** * Removes a capability from a global role. * * This is a container for WP_Global_Roles::remove_cap() to remove the * capability from the role. That is to say, that WP_Global_Roles::remove_cap() * implements the functionality, but it also makes sense to use this class, * because you don't need to enter the role name. * * @since 4.8.0 * @access public * * @param string $cap Capability name. */ public function remove_cap($cap) { unset($this->capabilities[$cap]); wp_global_roles()->remove_cap($this->name, $cap); }
function remove_global_role($role) { wp_global_roles()->remove_role($role); }