WP_Role::has_cap( string $cap )

Determines whether the role has the given capability.


Description Description

The capabilities is passed through the ‘role_has_cap’ filter. The first parameter for the hook is the list of capabilities the class has assigned. The second parameter is the capability name to look for. The third and final parameter for the hook is the role name.


Parameters Parameters

$cap

(string) (Required) Capability name.


Top ↑

Return Return

(bool) True if the role has the given capability. False otherwise.


Top ↑

Source 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 Associative array of capabilities for the role.
		 * @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

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.