WP_Role::remove_cap( string $cap )

Removes a capability from a role.


Capability name.

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.


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



User Contributed Notes

  1. Skip to note 5 content

    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 6 content

    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.