Codex

Function Reference/current user can

Contents

Description

Whether the current user has a certain capability. See: Roles and Capabilities.

Do not pass a custom role name to current_user_can(), as this is not guaranteed to work correctly. Instead, you may wish to try the check user role function put together by AppThemes.

Usage

 <?php current_user_can$capability$args ); ?> 

Parameters

$capability
(string) (required) capability or role name
Default: None
$args
(mixed) (optional) Any additional arguments that may be needed, such as a post ID. Some capability checks (like 'edit_post' or 'delete_page') require this be provided.
Default: None

Returns

(boolean)
  • true if the current user has got the capability.
  • false if the current user hasn't got the capability.

Examples

if ( current_user_can('moderate_comments') ) {
 echo 'The current user can moderate comments';
}
if ( current_user_can('edit_post', 123) ) {
 echo 'The current user can edit post 123'.
}

Changelog

Since: 2.0.0

Source Code

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

Related

Resources

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