Migrate from WP User Avatar to JJJ’s WP User Avatars

WP User Avatar, now commandeered by ProfilePress, is significantly more bloated than it once was.

There are a variety of alternatives to turn to if you want to replace it, but I’ve chosen (and recommend) WP User Avatars, maintained by WordPress core contributor John James Jacoby.

The migration here is pretty simple. WP User Avatar keeps a media ID in the database, so it’s easy to fetch that for each user and repurpose.

Activate both plugins on your site before running this migration. You can put the following script in a file and run it using WP-CLI’s eval-file command, or you can turn the foreach into a one-liner and run it with wp shell. You’ve got options, but however you want to do it, run it once:


$users = get_users();
foreach($users as $user) { 
  $media_id = get_user_meta($user->ID, 'wp_user_avatar', true); 
  if($media_id) { 
    wp_user_avatars_update_avatar($user->ID, (int) $media_id); 
}Code language: PHP (php)

This function uses WP User Avatars‘s core update function to generate the expected meta and save it back to the database.

Next up, check your own code for any references to old WP User Avatar functions. For example, I had a site where theme code was using get_wp_user_avatar_src directly. Ideally, you’ll want to swap out functions like this for calls to the WordPress core functions get_avatar() or get_avatar_url(), making your site more flexible in the face of changes like this in the future.

Tipget_wp_user_avatar_src accepted a named WordPress image size, whereas get_avatar() and get_avatar_url() only accept pixel values, so you’ll have to do a little translating there if you’re in that boat. You might have to dig into the WP User Avatars core functions or access the meta directly if the square images those functions generate won’t work for your use case.

Once you’ve removed any WP User Avatar-specific code, you can deactivate it and delete it. Good riddance.


Leave a Reply

Your email address will not be published. Required fields are marked *