Languages:
English •
日本語 •
(Add your language)
Description
Whether current user has capability or role.
Usage
<?php current_user_can( $capability , $object_id ); ?>
Parameters
- $capability
- (string) (required) Role or capability.
- 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_others_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