Hotel staff spying on guests

I stayed at the Hotel 1000 in Seattle last weekend. It was quite pleasant and I was going to give it a good rating and recommend it to friends and colleagues.

Then I logged into my LinkedIn profile and found this:

Screen Shot 2013-12-19 at 14.35.39

 

The more I think about it, the more it bothers me. When travelling and staying at hotels, I expect the hotels to respect my privacy.

Dear Hotel 1000, this is simply not cool. I hope this is not common practice at your hotel, as a guest I find this extremely creepy.

p.s. I mailed the hotel a link to my post at the same time as I posted it.

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.