W3cubDocs

/WordPress

user_can( int|WP_User $user, string $capability )

Whether a particular user has a specific capability.

Description

Parameters

$user

(int|WP_User) (Required) User ID or object.

$capability

(string) (Required) Capability name.

Return

(bool) Whether the user has the given capability.

Source

File: wp-includes/capabilities.php

function user_can( $user, $capability ) {
	if ( ! is_object( $user ) ) {
		$user = get_userdata( $user );
	}

	if ( ! $user || ! $user->exists() ) {
		return false;
	}

	$args = array_slice( func_get_args(), 2 );
	$args = array_merge( array( $capability ), $args );

	return call_user_func_array( array( $user, 'has_cap' ), $args );
}

Changelog

Version Description
3.1.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/user_can