Archive for the ‘Uncategorized’ Category

Changing Userlogin with a Persistent Object Cache


If you go and change the username for a WordPress user directly in the DB (the only way to do it) then you will likely run into cache issues if you use a persistent object cache like Memcached or Redis.

You can see how WP stores those cache items and derive the keys from that:
wp_cache_add($user->ID, $user, 'users');
wp_cache_add($user->user_login, $user->ID, 'userlogins');
wp_cache_add($user->user_email, $user->ID, 'useremail');
wp_cache_add($user->user_nicename, $user->ID, 'userslugs');

Then you could use WP CLI to clear them one by one:
wp cache delete oldusername userlogins

But that’s a hassle. Let’s cheat:
wp eval 'clean_user_cache(55555);'

Hello world!


Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!