WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_User::has_cap() WP 2.0.0

Whether the user has a specific capability.

While checking against a role in place of a capability is supported in part, this practice is discouraged as it may produce unreliable results.

Это метод класса: WP_User

Хуки из метода

true/false. Whether the user has the given capability, or, if $object_id is passed, whether the user has the given capability for that object.


$WP_User = new WP_User();
$var = $WP_User->has_cap( $cap );
$cap(строка) (обязательный)
Capability name.
$object_id,...(число) (обязательный)
ID of a specific object to check against if $cap is a "meta" capability. Meta capabilities such as edit_post and edit_user are capabilities used by by the map_meta_cap() function to map to primitive capabilities that a user or role has, such as edit_posts and edit_others_posts.


  • Смотрите: map_meta_cap()

Список изменений

С версии 2.0.0 Введена.

Код WP User::has cap: wp-includes/class-wp-user.php WP 5.2.4

public function has_cap( $cap ) {
	if ( is_numeric( $cap ) ) {
		_deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) );
		$cap = $this->translate_level_to_cap( $cap );

	$args = array_slice( func_get_args(), 1 );
	$args = array_merge( array( $cap, $this->ID ), $args );
	$caps = call_user_func_array( 'map_meta_cap', $args );

	// Multisite super admin has all caps by definition, Unless specifically denied.
	if ( is_multisite() && is_super_admin( $this->ID ) ) {
		if ( in_array( 'do_not_allow', $caps ) ) {
			return false;
		return true;

	 * Dynamically filter a user's capabilities.
	 * @since 2.0.0
	 * @since 3.7.0 Added the `$user` parameter.
	 * @param bool[]   $allcaps Array of key/value pairs where keys represent a capability name and boolean values
	 *                          represent whether the user has that capability.
	 * @param string[] $caps    Required primitive capabilities for the requested capability.
	 * @param array    $args {
	 *     Arguments that accompany the requested capability check.
	 *     @type string    $0 Requested capability.
	 *     @type int       $1 Concerned user ID.
	 *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
	 * }
	 * @param WP_User  $user    The user object.
	$capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this );

	// Everyone is allowed to exist.
	$capabilities['exist'] = true;

	// Nobody is allowed to do things they are not allowed to do.
	unset( $capabilities['do_not_allow'] );

	// Must have ALL requested caps.
	foreach ( (array) $caps as $cap ) {
		if ( empty( $capabilities[ $cap ] ) ) {
			return false;

	return true;