Purge All WordPress Users of a Particular Role

Bulk Delete WordPress Users

I needed to delete all of the subscriber level users on one of my sites recently, and couldn’t find an easy way to do it. My solution? Write some code. It was definitely quicker and easier to run this snippet than to manually delete over 7,700 users from my database. Drop this code into an admin page where you can run it as an administrator, and watch it go to work!

If you need to delete authors, editors, or some other role, simple switch “subscriber” on line 3 to your chosen role. Note: it must be a valid WordPress role registered in your site. This code leaves users with posts in the database. If you would like to remove users that have posts, remove the conditional on line 7 and it’s corresponding closing bracket on line 13. Be sure to modify the wp_delete_user function call on line 8 with it’s second argument – this will keep those user’s posts online and attribute them to whatever user ID you specify in the second argument.

[code language=”php”]<?php

$all_users = get_users( array( ‘role’ => ‘subscriber’ ) );

foreach( $all_users as $single_user ) {
$users_posts = get_posts( array( ‘author’ => $single_user->ID ) );
if( !$users_posts ) {
if( wp_delete_user( $single_user->ID ) ) {
echo ‘User ‘ . $single_user->ID . ‘ deleted.<br />’;
} else {
echo ‘Delete user ‘ . $single_user->ID . ‘ failed!<br />’;
}
}
}

?>[/code]

Disclaimer: This code is fast and aggressive. There is no “undoing” this operation. Use this at your own risk, data is NOT recoverable. Also, don’t believe everything you read online … you cannot perform the same function with raw MySQL without completely hosing your database – so don’t even try unless you REALLY know what you’re doing.

A Day at the Palm Beach Parks

There’s no need to use lots of words here – the pictures tell the story of our day exploring MacArthur Park and Phil Foster Park.

AutoGallery of Free Photoshop Textures

I just created shot these photos, created the gallery, and published to the site in less than 60 seconds total with the AutoMedia application. I’ve been working on the server-side plugin and have added a few new features that I think you’re going to like. The most dramatic change is the addition of the AutoGallery functionality that I promised six months ago. It’s working quite well, and this gallery should be proof enough of that. I’ll be committing the changes to the WordPress SVN after some further bug testing. Have a good weekend everyone!

As I stood in line to vote this morning with Tina, a new US citizen and first-time voter, she stated “In my country we didn’t have voting, we had genocide.” If that doesn’t make you proud to be American there’s something wrong with you. I am so happy to have been a part of that experience with her and share in her excitement. Good luck to all candidates and may the best man win!

Cruising on Grace

Greetings from beautiful Palm Beach, FL once again!

Tina and I spent some quality family time in Daytona Beach over the weekend where we attempted to catch catfish, ate lots of food, and went cruising on Grace. This was especially exciting for me because after all the adventures I’ve had with them aboard Grace, I’ve never actually been out on the water on her.

So here’s our photo-journal of the weekend:

And here’s a video from Silvana of our trip aboard Grace:

[youtube http://www.youtube.com/watch?v=cbWPVX3DNls%5D

And regardless of who you support, REMEMBER TO GO VOTE TOMORROW!