Jetpack_PostImages::from_gravatar PHP Method

from_gravatar() static public method

static public from_gravatar ( integer $post_id, integer $size = 96, string $default = false ) : Array
$post_id integer The post ID to check
$size integer
$default string The default image to use.
return Array containing details of the image, or empty array if none.
    static function from_gravatar($post_id, $size = 96, $default = false)
    {
        $post = get_post($post_id);
        $permalink = get_permalink($post_id);
        if (function_exists('wpcom_get_avatar_url')) {
            $url = wpcom_get_avatar_url($post->post_author, $size, $default, true);
            if ($url && is_array($url)) {
                $url = $url[0];
            }
        } else {
            $has_filter = has_filter('pre_option_show_avatars', '__return_true');
            if (!$has_filter) {
                add_filter('pre_option_show_avatars', '__return_true');
            }
            $avatar = get_avatar($post->post_author, $size, $default);
            if (!$has_filter) {
                remove_filter('pre_option_show_avatars', '__return_true');
            }
            if (!$avatar) {
                return array();
            }
            if (!preg_match('/src=["\']([^"\']+)["\']/', $avatar, $matches)) {
                return array();
            }
            $url = wp_specialchars_decode($matches[1], ENT_QUOTES);
        }
        return array(array('type' => 'image', 'from' => 'gravatar', 'src' => $url, 'src_width' => $size, 'src_height' => $size, 'href' => $permalink));
    }