WP_Role::has_cap() WordPress Method

The WP_Role::has_cap() method is used to check if a given role has a specific capability. If the role does not have the capability, false will be returned.

WP_Role::has_cap( string $cap ) #

Determines whether the role has the given capability.


Parameters

$cap

(string)(Required)Capability name.


Top ↑

Return

(bool) Whether the role has the given capability.


Top ↑

Source

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

	public function has_cap( $cap ) {
		/**
		 * Filters which capabilities a role has.
		 *
		 * @since 2.0.0
		 *
		 * @param bool[] $capabilities Array of key/value pairs where keys represent a capability name and boolean values
		 *                             represent whether the role has that capability.
		 * @param string $cap          Capability name.
		 * @param string $name         Role name.
		 */
		$capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name );

		if ( ! empty( $capabilities[ $cap ] ) ) {
			return $capabilities[ $cap ];
		} else {
			return false;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.