Make WordPress Core


Ignore:
Timestamp:
07/29/2024 01:57:11 AM (11 months ago)
Author:
peterwilsoncc
Message:

Users: Always use HTTPS URLs for Gravatar links.

Modifies gravatar image URLs to always use the HTTPS version from secure.gravatar.com.

Gravatar now redirects HTTP image requests to their HTTPS equivalent, resulting in redirects for sites running over an HTTP connection (is_ssl() === false). Since the introduction of HTTP/2 the use of sub-domains for different hashes ([1-3].gravatar.com) now represents a performance hinderance rather than improvement.

The scheme passed to get_avatar_data() is now ignored for the generation of Gravatar URLs but the setting retained to avoid introducing bugs for sites using either local avatars or third party providers.

Props neoxx, SergeyBiryukov, sippis, peterwilsoncc, mukesh27, costdev, dd32.
Fixes #37454.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r58807 r58822  
    43294329 *
    43304330 * @since 4.2.0
     4331 * @since 6.7.0 Gravatar URLs always use HTTPS.
    43314332 *
    43324333 * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
     
    43594360 *                                  Default is the value of the 'avatar_rating' option.
    43604361 *     @type string $scheme         URL scheme to use. See set_url_scheme() for accepted values.
     4362 *                                  For Gravatars this setting is ignored and HTTPS is used to avoid
     4363 *                                  unnecessary redirects. The setting is retained for systems using
     4364 *                                  the {@see 'pre_get_avatar_data'} filter to customize avatars.
    43614365 *                                  Default null.
    43624366 *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
     
    45094513    if ( $email_hash ) {
    45104514        $args['found_avatar'] = true;
    4511         $gravatar_server      = hexdec( $email_hash[0] ) % 3;
    4512     } else {
    4513         $gravatar_server = rand( 0, 2 );
    45144515    }
    45154516
     
    45214522    );
    45224523
    4523     if ( is_ssl() ) {
    4524         $url = 'https://secure.gravatar.com/avatar/' . $email_hash;
    4525     } else {
    4526         $url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash );
    4527     }
     4524    /*
     4525     * Gravatars are always served over HTTPS.
     4526     *
     4527     * The Gravatar website redirects HTTP requests to HTTPS URLs so always
     4528     * use the HTTPS scheme to avoid unnecessary redirects.
     4529     */
     4530    $url = 'https://secure.gravatar.com/avatar/' . $email_hash;
    45284531
    45294532    $url = add_query_arg(
    45304533        rawurlencode_deep( array_filter( $url_args ) ),
    4531         set_url_scheme( $url, $args['scheme'] )
     4534        $url
    45324535    );
    45334536
Note: See TracChangeset for help on using the changeset viewer.