Title: WP_Role::remove_cap
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Role::remove_cap( string $cap )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#user-contributed-notes)

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

Removes a capability from a role.

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

 `$cap`stringrequired

Capability name.

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

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

This setting is saved to the database (in table wp_options, field 'wp_user_roles'),
so you should run this only once, on theme/plugin activation and/or deactivation.

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

    ```php
    public function remove_cap( $cap ) {
    	unset( $this->capabilities[ $cap ] );
    	wp_roles()->remove_cap( $this->name, $cap );
    }
    ```

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

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

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

Retrieves the global [WP_Roles](https://developer.wordpress.org/reference/classes/wp_roles/) instance and instantiates it if necessary.

  | 
| [WP_Roles::remove_cap()](https://developer.wordpress.org/reference/classes/wp_roles/remove_cap/)`wp-includes/class-wp-roles.php` |

Removes a capability from role.

  |

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#comment-content-3681)
 2.    [Yogesh Chatrola](https://profiles.wordpress.org/yogesh96016/)  [  6 years ago  ](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/#comment-3681)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%23comment-3681)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%23comment-3681)
 4.      ```php
         $author = get_role( 'author' );
     
             $caps = array (
                 'edit_posts',
                 'edit_published_posts',
                 'publish_posts',
                 'delete_posts',
                 'delete_published_posts',
             );
     
             foreach ( $caps as $cap ) {
     
                 $author->remove_cap( $cap );
             }
         ```
     
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%3Freplytocom%3D3681%23feedback-editor-3681)
 6.   [Skip to note 5 content](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#comment-content-4014)
 7.    [Akira Tachibana](https://profiles.wordpress.org/atachibana/)  [  6 years ago  ](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/#comment-4014)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%23comment-4014)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%23comment-4014)
 9.  From Codex
 10.     ```php
         /**
          * Don't let editors read private posts.
          *
          * You should call the function when your plugin is activated.
          *
          * @uses WP_Role::remove_cap()
          */
         function remove_editor_read_private_posts() {
     
         	// get_role returns an instance of WP_Role.
         	$role = get_role( 'editor' );
         	$role->remove_cap( 'read_private_posts' );
         }
         ```
     
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%3Freplytocom%3D4014%23feedback-editor-4014)
 12.  [Skip to note 6 content](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/?output_format=md#comment-content-4016)
 13.   [Akira Tachibana](https://profiles.wordpress.org/atachibana/)  [  6 years ago  ](https://developer.wordpress.org/reference/classes/wp_role/remove_cap/#comment-4016)
 14. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%23comment-4016)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%23comment-4016)
 15. From Codex, Remove multiple capabilities example
 16.     ```php
         /**
          * Remove capabilities from editors.
          *
          * Call the function when your plugin/theme is activated.
          */
         function wpcodex_set_capabilities() {
     
             // Get the role object.
             $editor = get_role( 'editor' );
     
         	// A list of capabilities to remove from editors.
             $caps = array(
                 'moderate_comments',
                 'manage_categories',
                 'manage_links',
                 'edit_others_posts',
                 'edit_others_pages',
                 'delete_posts',
             );
     
             foreach ( $caps as $cap ) {
     
                 // Remove the capability.
                 $editor->remove_cap( $cap );
             }
         }
         add_action( 'init', 'wpcodex_set_capabilities' );
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_role%2Fremove_cap%2F%3Freplytocom%3D4016%23feedback-editor-4016)

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