WordPress.org

Ready to get started?Download WordPress

Codex

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

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

Capabilities Parameters

Here is a list of current $capability strings (keep in mind plugins may adjust the capabilities array).

  • activate_plugins (boolean)
  • add_users (boolean)
  • create_users (boolean)
  • delete_others_pages (boolean)
  • delete_others_posts (boolean)
  • delete_pages (boolean)
  • delete_plugins (boolean)
  • delete_posts (boolean)
  • delete_private_pages (boolean)
  • delete_private_posts (boolean)
  • delete_published_pages (boolean)
  • delete_published_posts (boolean)
  • delete_themes (boolean)
  • delete_users (boolean)
  • edit_dashboard (boolean)
  • edit_others_pages (boolean)
  • edit_others_posts (boolean)
  • edit_pages (boolean)
  • edit_plugins (boolean)
  • edit_posts (boolean)
  • edit_private_pages (boolean)
  • edit_private_posts (boolean)
  • edit_published_pages (boolean)
  • edit_published_posts (boolean)
  • edit_themes (boolean)
  • edit_theme_options (boolean)
  • import (boolean)
  • install_plugins (boolean)
  • install_themes (boolean)
  • list_users (boolean)
  • manage_categories (boolean)
  • manage_links (boolean)
  • manage_options (boolean)
  • moderate_comments (boolean)
  • promote_users (boolean)
  • publish_pages (boolean)
  • publish_posts (boolean)
  • read (boolean)
  • read_private_pages (boolean)
  • read_private_posts (boolean)
  • remove_users (boolean)
  • switch_themes (boolean)
  • unfiltered_html (boolean)
  • unfiltered_upload (boolean)
  • update_core (boolean)
  • update_plugins (boolean)
  • update_themes (boolean)
  • upload_files (boolean)
  • level_10 (boolean) - deprecated
  • level_9 (boolean) - deprecated
  • level_8 (boolean) - deprecated
  • level_7 (boolean) - deprecated
  • level_6 (boolean) - deprecated
  • level_5 (boolean) - deprecated
  • level_4 (boolean) - deprecated
  • level_3 (boolean) - deprecated
  • level_2 (boolean) - deprecated
  • level_1 (boolean) - deprecated
  • level_0 (boolean) - deprecated

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.