WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/current user can

Contents

Description

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

Usage

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

Parameters

$capability
(string) (required) A capability. This is case-sensitive, and should be all lowercase.
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 the capability.
  • false if the current user does not have the capability.

Caution: current_user_can returns true even for a non existing or a junk post id

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';
}

Notes

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

Changelog

Since: 2.0.0

Source Code

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

Resources

Related

User Capabilities: user_can(), current_user_can(), current_user_can_for_blog()

Current User Functions: get_current_user_id(), get_currentuserinfo(), wp_get_current_user(), wp_set_current_user(), current_user_can(), current_user_can_for_blog()

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