Reblogging is back!
Old photos my dad took during a volcanic erruption
A great way to start a new year!
What could be better than starting off 2012 with Ian Pooley?
Play it again: Siri hacked to play piano
Trailer: The Hobbit
This trailer got me super excited!
The Hobbit won’t be out until next December, but a trailer is out to tease us.
When the extended edition eventually comes out on DVD it’s going to be extremely difficult to watch the entire Lord of the Rings series in one day.
Quick hack to delete WordPress users based on their role
Someone asked for a way to delete 15000 users from WordPress based on their role.
I have this snippet I’ve used before, not sure how well it will perform for 15000, but I’m sure it can be tuned to do that 🙂
<?php
define( 'WP_USE_THEMES', false );
require_once( './wp-load.php' );
require_once( ABSPATH.'wp-admin/includes/user.php' );
$role = 'subscriber'; // The role to kill.
$reassign = 1; // The user that all posts will fall back to, other wise they will be deleted.
$this_role = sprintf( 's:%d:"%s";', strlen( $role ), $role );
$results = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' AND meta_value LIKE %s", '%' . $wpdb->esc_like( $this_role ) . '%' ) );
if ( $results ) {
foreach ( $results as $user_id ) {
wp_delete_user( $user_id, $reassign );
}
}
(Edited to skip the wpdb->users table from the mix)
(Updated: 2017-01-06, works for WordPress 4.x, added a version which generates a PHP file with each of the delete commands)
Here is a version where you can pipe the output into a separate PHP file, review and then run.
<?php
define( 'WP_USE_THEMES', false );
require_once( './wp-load.php' );
$role = 'subscriber'; // The role to kill.
$reassign = 1; // The user that all posts will fall back to, other wise they will be deleted.
$this_role = sprintf( 's:%d:"%s";', strlen( $role ), $role );
$results = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' AND meta_value LIKE %s", '%' . $wpdb->esc_like( $this_role ) . '%' ) );
if ( $results ) {
echo <<<HTML
<?php
define( 'WP_USE_THEMES', false );
require_once( './wp-load.php' );
require_once( ABSPATH.'wp-admin/includes/user.php' );
HTML;
foreach ( $results as $user_id ) {
echo "wp_delete_user( $user_id, $reassign );\n";
}
}
When you run it, e.g. like this:
php this-snippet.php > output.php
The output should generate something like
<?php define( 'WP_USE_THEMES', false ); require_once( './wp-load.php' ); require_once( ABSPATH.'wp-admin/includes/user.php' ); wp_delete_user( 2, 1 ); wp_delete_user( 3, 1 ); ... wp_delete_user( 15000, 1 );
Which you can then review before you decide to delete those 15000 users.
Introducing WordAds
Team Data+Stats+Ads ftw!
MNPP ftw!
My brother pointed me to MNPP (Mac + Nginx + Percona + PHP or Python).
I find MAMP to be such a mess that I can’t stand using it. Switching over to MNPP, hoping that works better.
I love Nginx, Percona and my Mac, switching between PHP and Python is a big plus.
You must be logged in to post a comment.