Skip to content

Instantly share code, notes, and snippets.

@kodie
Created October 21, 2020 20:16
Show Gist options
  • Save kodie/b855779f5ff5e3fa24adfb0d36a48906 to your computer and use it in GitHub Desktop.
Save kodie/b855779f5ff5e3fa24adfb0d36a48906 to your computer and use it in GitHub Desktop.
Adds an "image_size" argument to get_avatar_data so that avatar image sizes can be defined by the image size name in WordPress
<?php
// Adds an "image_size" argument to get_avatar_data so that avatar image sizes
// can be defined by the image size name (requires the get_image_sizes function)
// (https://gist.github.com/kodie/19d027d2c0e2297d1e09b7b71505e774)
// Example: get_avatar_url($user_id, array('image_size' => 'thumbnail'));
add_filter('pre_get_avatar_data', 'avatar_data_image_size_arg', 10, 2);
function avatar_data_image_size_arg($args, $id_or_email) {
if (isset($args['image_size'])) {
if ($size = get_image_sizes($args['image_size'])) {
$args['height'] = $size['height'];
$args['width'] = $size['width'];
}
}
return $args;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment