/** * @param int $post_id The post ID to check * @param int $size * @param string $default 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)); }
protected function get_avatar_url($email, $avatar_size = 96) { $avatar_url = wpcom_get_avatar_url($email, $avatar_size, '', true); if (!$avatar_url || is_wp_error($avatar_url)) { return ''; } return esc_url_raw(htmlspecialchars_decode($avatar_url[0])); }