How to use the current_user_can function in WordPress

Last updated:

This article explains how to use the current_user_can function in WordPress. It also introduces the parameters, return value, and examples of usage.

What is the current_user_can function?

Returns whether the current user has the specified capability or not.


The current_user_can function is written as follows.

current_user_can( $capability, $args )


2 parameters can be specified in the current_user_can function.

Parameter nameDescription
$capability (Required)Capability name
$argsAdditional Parameters


Specify the capability name. Required.

It is also possible to specify a role (admin/editor/contributor/contributor/subscriber) for $capability, but this may return unintended results.


Specify additional parameters, such as $post_id. It is optional.


Returns true if the current user has the specified capability, false if not.

How to use the current_user_can function

Explains how to use the current_user_can function to check if the current user has article editing capability.

Specifying Capability

edit_posts is a parameter of current_user_can function that represents the capability to edit an article.

It’s a string, so use single quotes to enclose the parameters.

current_user_can( 'edit_posts' )

Specified in the conditional expression of the IF statement

Check to see if the current user is authorized by specifying the current_user_can function as a conditional expression in the IF statement.

if( current_user_can( 'edit_posts' ) ){
    //Processing for users with article editing rights

Example of using the current_user_can function

An example of the use of the current_user_can function is shown below.

Supported Versions

WordPress 2.0.0 or later

Source code

The current_user_can function is defined in “wp-includes/capabilities.php”.

Most Popular Articles

  1. What’s new in WordPress 5.6? New Features and Changes
  2. How to Add width/height to Images in WordPress
  3. What’s New in WordPress 5.5.3? Fixed 1 Bug
  4. WordPress 5.6 jQuery version updates and solution for jQuery
  5. WordPress Version List (Release Date/Code Name)
  6. What’s new in WordPress 5.5? New Features and Changes
  7. What’s New in WordPress 5.5.2? Fixed 10 security issues
  8. How to check if the current user is Administrator in WordPress
  9. Vulnerability of File Manager WordPress plugin and Solutions
  10. Recommend Premium Themes for WordPress (By Usage)

New Articles

go to top