user_has_cap WordPress Filter Hook

The user_has_cap hook is used to check if a user has a certain capability. If the user does not have the capability, they will not be able to perform the action.

apply_filters( 'user_has_cap', bool[] $allcaps, string[] $caps, array $args, WP_User $user ) #

Dynamically filter a user’s capabilities.


Parameters

$allcaps

(bool[])Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.

$caps

(string[])Required primitive capabilities for the requested capability.

$args

(array)Arguments that accompany the requested capability check.

  • (string) Requested capability.
  • '1'
    (int) Concerned user ID.
  • '...$2'
    (mixed) Optional second and further parameters, typically object ID.

$user

(WP_User)The user object.


Top ↑

More Information

Passing in a numeric value to WP_User::has_cap() object has been deprecated. Passing a numeric value will generate a deprecated option warning if debugging mode is enabled via wp_config.php:

Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.

This will occur if a plugin or a theme calls has_cap directly. The plugin or theme needs to be updated to use the new roles and capabilities classes.


Top ↑

Source

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

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
3.7.0Added the $user parameter.
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.