user_has_cap
Filter HookDescription
Dynamically filter a user's capabilities. }Hook Information
File Location |
wp-includes/class-wp-user.php
View on GitHub
|
Hook Type | Filter |
Line Number | 815 |
Hook Parameters
Type | Name | Description |
---|---|---|
bool[]
|
$allcaps
|
Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability. |
string[]
|
$caps
|
Required primitive capabilities for the requested capability. |
array
|
$args
|
{ Arguments that accompany the requested capability check. |
WP_User
|
$user
|
The user object. |
Usage Examples
Basic Usage
<?php
// Hook into user_has_cap
add_filter('user_has_cap', 'my_custom_filter', 10, 4);
function my_custom_filter($allcaps, $caps, $args, $user) {
// Your custom filtering logic here
return $allcaps;
}
Source Code Context
wp-includes/class-wp-user.php:815
- How this hook is used in WordPress core
<?php
810 * @type int $1 Concerned user ID.
811 * @type mixed ...$2 Optional second and further parameters, typically object ID.
812 * }
813 * @param WP_User $user The user object.
814 */
815 $capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this );
816
817 // Everyone is allowed to exist.
818 $capabilities['exist'] = true;
819
820 // Nobody is allowed to do things they are not allowed to do.
PHP Documentation
<?php
/**
* 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.
*/
Quick Info
- Hook Type: Filter
- Parameters: 4
- File: wp-includes/class-wp-user.php
Related Hooks
Related hooks will be displayed here in future updates.