开发者

Is there a Gravatar signup link to pre-populate the user's email address?

开发者 https://www.devze.com 2023-04-04 03:26 出处:网络
I would expect something like this to work开发者_运维知识库 http://en.gravatar.com/site/signup?email=user%40example.com

I would expect something like this to work开发者_运维知识库

http://en.gravatar.com/site/signup?email=user%40example.com

To avoid the user having to retype their email.


I noticed this wordpress package that handled it (and a TON of other stuff) for the user, so I dug through his code a bit, and he used this PHP function:

/**
 * Get URL to locale gravatar signup page
 *
 * @since 2.0
 * @param string $email Email address that should be apended
 * @return string $gse_url URL of locale signup page
 */
function gravatar_signup_encouragement_locale_signup_url( $email = '' ) {
    /* translators: Locale gravatar.com, e.g. sr.gravatar.com for Serbian */
    $gse_locale_url = _x( 'en.gravatar.com', 'Locale gravatar.com, e.g. sr.gravatar.com for Serbian', 'gse_textdomain' );

    /* Check if it's really locale.gravatar.com */
    if ( preg_match( '|^[A-Z_%+-]+.gravatar+.com|i', $gse_locale_url ) ) {
        $gse_locale_url = $gse_locale_url;
    } else {
        $gse_locale_url = 'en.gravatar.com';
    }

    /* If email exists, append it */
    if ( empty( $email ) ) {
        $gse_url = "http://" . $gse_locale_url . '/site/signup/';
    } else {
        $encoded_email = urlencode( $email );
        $gse_url = "http://" . $gse_locale_url . '/site/signup/' . $encoded_email;
    }

    return $gse_url;
}

Unfortunately, this probably doesn't work anymore since Wordpress took over the form with oauth accounts, so here is my Ruby on Rails converted solution. The important bit is the fact that the HTTP param user_email exists and works:

  def gravatar_create_url(user)
     user_email = u user.email.downcase
     "https://signup.wordpress.com/signup/?ref=oauth2&user_email=#{user_email}&oauth2_redirect=bf551c93d83b96478db51481a9cbe97e%40https%3A%2F%2Fpublic-api.wordpress.com%2Foauth2%2Fauthorize%2F%3Fclient_id%3D1854%26response_type%3Dcode%26blog_id%3D0%26state%3D331f9ecba5fcab15e2168e1231f7be2a4b1b8cd24dd6f90b3672fb5159d7b590%26redirect_uri%3Dhttps%253A%252F%252Fen.gravatar.com%252Fconnect%252F%253Faction%253Drequest_access_token%26jetpack-code%26jetpack-user-id%3D0%26action%3Doauth2-login&wpcom_connect=1"
  end

I'm not sure about all those other redirect params, as those may change over time with how Wordpress has taken over Gravatar, but hopefully this gets you in the right direction.


Just to distill toobulkeh's answer (which should be accepted), and make it implementation agnostic...

Use the user_email query param on the signup page url

https://signup.wordpress.com/signup/?user_email=user%40example.com


It has changed. You now have to calculate the md5 hash first. Like this:

http://www.gravatar.com/avatar/[MD5 of e-mail]?s=[size of gravatar]

eg: http://www.gravatar.com/avatar/1f8b4ac238826420d85929df0cdc00f4?s=255

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号