WordPress at a glance

user_can() WP 1.0

Whether a particular user has a specific capability.

Works based on: WP_User::has_cap()

No Hooks.

Return

true/false. Whether the user has the given capability.

Usage

user_can( $user, $capability );
$user(int/WP_User) (required)
User ID or object.
$capability(string) (required)
Capability name.

Code of user_can: wp-includes/capabilities.php VER 5.0.1

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

Related Functions

From tag: Roles capabilities

No comments
    Hello, !     Log In . Register