Title: WP_Roles::add_cap
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_Roles::add_cap( string $role, string $cap, bool $grant = true )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#wp--skip-link--target)

Adds a capability to role.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#parameters)󠁿

 `$role`stringrequired

Role name.

`$cap`stringrequired

Capability name.

`$grant`booloptional

Whether role is capable of performing capability.

Default:`true`

## 󠀁[More Information](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#more-information)󠁿

Changing the capabilities of a role is persistent, meaning the added capability 
will stay in effect until explicitly revoked.

This setting is saved to the database (in table wp_options, field wp_user_roles),
so it might be better to run this on theme/plugin activation.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#source)󠁿

    ```php
    public function add_cap( $role, $cap, $grant = true ) {
    	if ( ! isset( $this->roles[ $role ] ) ) {
    		return;
    	}

    	$this->roles[ $role ]['capabilities'][ $cap ] = $grant;
    	if ( $this->use_db ) {
    		update_option( $this->role_key, $this->roles );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-roles.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-roles.php#L232)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-roles.php#L232-L241)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#related)󠁿

| Uses | Description | 
| [update_option()](https://developer.wordpress.org/reference/functions/update_option/)`wp-includes/option.php` |

Updates the value of an option that was already added.

  |

| Used by | Description | 
| [WP_Role::add_cap()](https://developer.wordpress.org/reference/classes/wp_role/add_cap/)`wp-includes/class-wp-role.php` |

Assign role a capability.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_roles/add_cap/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_roles%2Fadd_cap%2F)
before being able to contribute a note or feedback.