Created
October 21, 2020 20:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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