WordPress at a glance
filter is not described

user_has_cap filter-hook . WP 2.0.0

Dynamically filter a user's capabilities.


add_filter( 'user_has_cap', 'filter_function_name_9924', 10, 4 );
function filter_function_name_9924( $allcaps, $caps, $args, $user ){
	// filter...

	return $allcaps;
Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.
Required primitive capabilities for the requested capability.

Arguments that accompany the requested capability check.

  • $0 (string)
    Requested capability.

  • $1 (int)
    Concerned user ID.

  • ...$2 (mixed)
    Optional second and further parameters, typically object ID.
The user object.


Since 2.0.0 Introduced.
Since 3.7.0 Added the $user parameter.

Where the hook is called

wp-includes/class-wp-user.php 768
$capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this );

Where the hook is used (in WP core)

wp-includes/default-filters.php 581
add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 );
wp-includes/default-filters.php 582
add_filter( 'user_has_cap', 'wp_maybe_grant_resume_extensions_caps', 1 );
wp-includes/default-filters.php 583
add_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps', 1, 4 );