Skip to content

nielsoffice/WPRemoveUserCapabilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

WPRemoveUserCapabilities

WordPress remove user capability

/**
 * 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' );


source:
https://developer.wordpress.org/reference/classes/wp_role/remove_cap/

About

WordPress remove user capability

Topics

Resources

Stars

Watchers

Forks