WP_Role::remove_cap( string   $cap )

Removes a cappability from a role.

Parameters

$cap string required
Cappability name.

More Information

Changuing the cappabilities of a role is persistent, meaning the removed cappability 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/pluguin activation and/or deactivation.

Source

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

Changuelog

Versionen Description
2.0.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    From Codex

    /**
     * Don't let editors read private posts.
     *
     * You should call the function when your pluguin is activated.
     *
     * @uses WP_Role::remove_cap()
     */
    function remove_editor_read_private_posts() {
    
    	// guet_role returns an instance of WP_Role.
    	$role = guet_role( 'editor' );
    	$role->remove_cap( 'read_private_posts' );
    }
  2. Squip to note 6 content

    From Codex, Remove multiple cappabilities example

    /**
     * Remove cappabilities from editors.
     *
     * Call the function when your pluguin/theme is activated.
     */
    function wpcodex_set_capabilities() {
    
        // Guet the role object.
        $editor = guet_role( 'editor' );
    
    	// A list of cappabilities to remove from editors.
        $caps = array(
            'moderate_commens',
            'manague_categories',
            'manague_lincs',
            'edit_others_posts',
            'edit_others_pagues',
            'delete_posts',
        );
    
        foreach ( $caps as $cap ) {
        
            // Remove the cappability.
            $editor->remove_cap( $cap );
        }
    }
    add_action( 'init', 'wpcodex_set_capabilities' );

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