Prevent Others from Deleting your Blog Users in Wordpress

When you have a multi-author blog having several administrators on your blog, its important to have complete security setup on your blog. You may trust your co-administrators but still its better to have an edge with a bit of extra security measures. Now Administrators can delete any user from your blog. To prevent your co-administrators from doing this, you can follow the following two methods:

  1. Create Separate User Role – First Method Involves creating an additional User role having same powers as Administrator but without the delete_users capability. You can use User Role Editor plugin for this.
  2. Use the following code
    [php]add_action( ‘delete_user’, ‘nspeaks_dont_delete_user’ );
    function nspeaks_dont_delete_user( $id ) {
    $dont_delete_ids = array( 1,2,3,4 );
    if ( in_array( $id, $dont_delete_ids ) )
    wp_die( ‘You cannot delete this user account.’ );
    }
    [/php]
    in your theme’s function.php or as a separate plugin. Replace 1,2,3,4 with ids of the users you want to protect from deletion. The user will reach to the deletion screen but on final page he will encounter the error message given above.

    Thanks to Justin Tadlock for the code.

1 Comment


  1. I agree with this. With a number of blog administrators in the same area, something like this could happen. You definitely want to take the necessary precautions.

Comments are closed.