コード例 #1
0
/**
 * Return the users avatar
 *
 * @param object $user
 * @param int $width
 * @param int $height
 * @param bool $crop. (default: true)
 * @param bool $try_normal. (default: true)
 * @return string
 */
function hma_get_avatar($user = null, $width, $height, $crop = true, $try_normal = true)
{
    $user = hma_parse_user($user);
    // Try to use avatar option classes
    if (!empty($user->user_avatar_option)) {
        $hma_avatar_option = hma_get_avatar_option($user->user_avatar_option);
        $hma_avatar_option->set_user($user);
        if (is_a($hma_avatar_option, 'hma_SSO_Avatar_Option')) {
            $avatar = $hma_avatar_option->get_avatar("width={$width}&height={$height}&crop={$crop}");
            if ($avatar) {
                return $avatar;
            }
        }
    }
    if ($avatar = hma_get_avatar_upload($user, $width, $height, $crop)) {
        return $avatar;
    } elseif ($avatar = apply_filters('hma_get_avatar_fallback', null, $user, $width, $height, $crop)) {
        return $avatar;
    } elseif ($try_normal === true) {
        preg_match('/src=\'([^\']*)/', get_avatar($user->user_email, $width), $matches);
        return $matches[1];
    }
}
コード例 #2
0
/**
 * Return the users profile url
 *
 * @todo refactor out $authordata and hm_parse_user();
 * @param object $authordata. (default: null)
 * @return string
 */
function hma_get_user_url($authordata = null)
{
    if (!$authordata) {
        global $authordata;
    }
    $authordata = hma_parse_user($authordata);
    return apply_filters('hma_user_url', home_url(hma_get_user_profile_rewrite_slug() . '/' . $authordata->user_nicename . '/'));
}
コード例 #3
0
/**
 * hma_replace_avatar function.
 *
 * @param string $avatar
 * @param mixed $id_or_email
 * @param int $size
 * @param string $default
 * @param string $alt. (default: null)
 * @todo email verification should use is_email
 * @return string
 */
function hma_replace_avatar($avatar, $id_or_email, $size, $default, $alt = null)
{
    // If the default is supplied and an email - don't hook in (as the avatar is handled through wp-admin settings)
    if (is_string($id_or_email) && strpos($id_or_email, '@') > 0 && $default) {
        return $avatar;
    }
    $user = hma_parse_user($id_or_email);
    if (!$user) {
        return $avatar;
    }
    $src = hma_get_avatar($user, $size, $size, true, false);
    if (!$src) {
        return $avatar;
    }
    return '<img alt="' . $alt . '" src="' . $src . '" class="avatar avatar-' . $size . ' photo" height="' . $size . '" width="' . $size . '" />';
}