WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/current user can

Description

Whether current user has capability or role.

Usage

 <?php current_user_can$capability ); ?> 

Parameters

$capability
(string) (required) capability or role name.
Default: None
$object_id
(int) (optional) Recommended when checking meta capabilities such as the capabilities defined in the `map_meta_cap` function i.e 'edit_post', 'edit_other_posts', 'read_post' etc. If omitted you may receive an 'Undefined offset: 0' warning (this is because the `current_user_can` function eventually calls `map_meta_cap` which when checking against meta capabilities expects an array but is only supplied a single value)
Default: None

Returns

(boolean) 
current user has capability or role.

Notes

For additional information on the 'undefined index 0' warning please see this detailed response on the WordPress Stack Exchange.

current_user_can( $capability ) will aways return true if user is Super Admin, unless specifically denied - see inline source code on https://developer.wordpress.org/reference/classes/wp_user/has_cap/

Changelog

Since: 2.0.0

Source Code

current_user_can() is located in wp-includes/capabilities.php.

Related

Roles_and_Capabilities

See also index of Function Reference and index of Template Tags.