Retrieve all of the role capabilities and merge with individual capabilities.

Description Description

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.

Return Return

(array) List of all capabilities for the user.

Top ↑

Source Source

File: wp-includes/class-wp-user.php

	public function get_role_caps() {
		$switch_site = false;
		if ( is_multisite() && $this->site_id != get_current_blog_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 ) {

		return $this->allcaps;

Top ↑

Changelog Changelog

Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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