public static function get_avatar_url($id_or_email, $size = 96, $default = '', $force_display = false)
{
// Don't bother adding the __return_true filter if it's already there.
$has_filter = has_filter('pre_option_show_avatars', '__return_true');
if ($force_display && !$has_filter) {
add_filter('pre_option_show_avatars', '__return_true');
}
$avatar = get_avatar($id_or_email, $size, $default);
if ($force_display && !$has_filter) {
remove_filter('pre_option_show_avatars', '__return_true');
}
// If no data, fail out.
if (is_wp_error($avatar) || !$avatar) {
return array(null, null);
}
// Pull out the URL. If it's not there, fail out.
if (!preg_match('/src=["\']([^"\']+)["\']/', $avatar, $url_matches)) {
return array(null, null);
}
$url = wp_specialchars_decode($url_matches[1], ENT_QUOTES);
// Pull out the class, but it's not a big deal if it's missing.
$class = '';
if (preg_match('/class=["\']([^"\']+)["\']/', $avatar, $class_matches)) {
$class = wp_specialchars_decode($class_matches[1], ENT_QUOTES);
}
return array($url, $class);
}