function get_author($author, $show_email = false)
{
if (isset($author->comment_author_email) && !$author->user_id) {
$ID = 0;
$login = '';
$email = $author->comment_author_email;
$name = $author->comment_author;
$first_name = '';
$last_name = '';
$URL = $author->comment_author_url;
$avatar_URL = $this->api->get_avatar_url($author);
$profile_URL = 'https://en.gravatar.com/' . md5(strtolower(trim($email)));
$nice = '';
$site_id = -1;
// Comment author URLs and Emails are sent through wp_kses() on save, which replaces "&" with "&"
// "&" is the only email/URL character altered by wp_kses()
foreach (array('email', 'URL') as $field) {
${$field} = str_replace('&', '&', ${$field});
}
} else {
if (isset($author->user_id) && $author->user_id) {
$author = $author->user_id;
} elseif (isset($author->user_email)) {
$author = $author->ID;
} elseif (isset($author->post_author)) {
// then $author is a Post Object.
if (0 == $author->post_author) {
return null;
}
/**
* Filter whether the current site is a Jetpack site.
*
* @module json-api
*
* @since 3.3.0
*
* @param bool false Is the current site a Jetpack site. Default to false.
* @param int get_current_blog_id() Blog ID.
*/
$is_jetpack = true === apply_filters('is_jetpack_site', false, get_current_blog_id());
$post_id = $author->ID;
if ($is_jetpack && (defined('IS_WPCOM') && IS_WPCOM)) {
$ID = get_post_meta($post_id, '_jetpack_post_author_external_id', true);
$email = get_post_meta($post_id, '_jetpack_author_email', true);
$login = '';
$name = get_post_meta($post_id, '_jetpack_author', true);
$first_name = '';
$last_name = '';
$URL = '';
$nice = '';
} else {
$author = $author->post_author;
}
}
if (!isset($ID)) {
$user = get_user_by('id', $author);
if (!$user || is_wp_error($user)) {
trigger_error('Unknown user', E_USER_WARNING);
return null;
}
$ID = $user->ID;
$email = $user->user_email;
$login = $user->user_login;
$name = $user->display_name;
$first_name = $user->first_name;
$last_name = $user->last_name;
$URL = $user->user_url;
$nice = $user->user_nicename;
}
if (defined('IS_WPCOM') && IS_WPCOM && !$is_jetpack) {
$active_blog = get_active_blog_for_user($ID);
$site_id = $active_blog->blog_id;
$profile_URL = "https://en.gravatar.com/{$login}";
} else {
$profile_URL = 'https://en.gravatar.com/' . md5(strtolower(trim($email)));
$site_id = -1;
}
$avatar_URL = $this->api->get_avatar_url($email);
}
$email = $show_email ? (string) $email : false;
$author = array('ID' => (int) $ID, 'login' => (string) $login, 'email' => $email, 'name' => (string) $name, 'first_name' => (string) $first_name, 'last_name' => (string) $last_name, 'nice_name' => (string) $nice, 'URL' => (string) esc_url_raw($URL), 'avatar_URL' => (string) esc_url_raw($avatar_URL), 'profile_URL' => (string) esc_url_raw($profile_URL));
if ($site_id > -1) {
$author['site_ID'] = (int) $site_id;
}
return (object) $author;
}