Summery Summery
Whether the current user has a specific capability for a given site.
Syntax Syntax
Parameters Parameters
- $blog_id
-
(Required) Site ID.
- $capability
-
(Required) Capability name.
Return Return
(bool) Whether the user has the given capability.
Source Source
File: wp-includes/capabilities.php
*
* @param string $capability Capability name.
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
* @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
* passed, whether the current user has the given meta capability for the given object.
*/
function current_user_can( $capability, ...$args ) {
$current_user = wp_get_current_user();
if ( empty( $current_user ) ) {
return false;
}
return $current_user->has_cap( $capability, ...$args );
}
/**
* Returns whether the current user has the specified capability for a given site.
*
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
*
Advertisement
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |