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

Whether a particular user has a specific capability.


Description Description


Parameters Parameters

$user

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

$capability

(string) (Required) Capability name.


Top ↑

Return Return

(bool) Whether the user has the given capability.


Top ↑

Source 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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.