Überspringen zu Hauptinhalt

Clean unwanted Roles in WordPress

geralt / Pixabay

Sometimes when a plugin is removed the additional user roles still remain. You might want to get rid of them. Unfortunately it is not that easy as one would expect. Here is how to remove unwanted user roles:

First of all, make sure you get the right names so you can adress them perfectly to remove them in the second step. Add this in your child themes function php and navigate to the backend to see the roles printed out:

//show roles
$wp_roles = new WP_Roles();
$names = $wp_roles->get_names();

if ( class_exists( 'BackWPup' ) ) {

$wp_roles = new WP_Roles();


Now that you know the names delete them. Add them to the array before deleting them. This example contains the BBPress roles left after uninstalling the BBpress forum plugin.

add_action( 'admin_init', 'clean_unwanted_caps' );
function clean_unwanted_caps(){
//add your roles here in the array to delete them on preocession of this script
$delete_caps = array('bbp_keymaster ', 'bbp_participant');
  global $wp_roles;
  foreach ($delete_caps as $cap) {
    foreach (array_keys($wp_roles->roles) as $role) {
      $wp_roles->remove_cap($role, $cap);


Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

An den Anfang scrollen