WP_Role::remove_cap( string $cap )

Removes a capability from a role.


$cap string Required
Capability name.

Top ↑

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.


Top ↑


File: wp-includes/class-wp-role.php. View all references

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

Top ↑


Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by Akira Tachibana

    From Codex

     * 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' );
  2. Skip to note 3 content
    Contributed by Akira Tachibana

    From Codex, Remove multiple capabilities example

     * 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(
        foreach ( $caps as $cap ) {
            // Remove the capability.
            $editor->remove_cap( $cap );
    add_action( 'init', 'wpcodex_set_capabilities' );

You must log in before being able to contribute a note or feedback.