Make WordPress Core


Ignore:
Timestamp:
07/12/2016 11:31:58 AM (8 years ago)
Author:
ocean90
Message:

Resource Hints: Remove schemes from dns-prefetch resource hint outputs.

"wordpress.org", "http://wordpress.org", and "https://wordpress.org" should all have the same DNS lookup.
Also, replace \r\n with \n and ensure that invalid URLs are skipped.

Props niallkennedy, peterwilsoncc.
Fixes #37240.

File:
1 edited

Legend:

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

    r38029 r38036  
    28162816         */
    28172817        $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
    2818         $urls = array_unique( $urls );
    2819 
    2820         foreach ( $urls as $url ) {
     2818
     2819        foreach ( $urls as $key => $url ) {
    28212820            $url = esc_url( $url, array( 'http', 'https' ) );
     2821            if ( ! $url ) {
     2822                unset( $urls[ $key ] );
     2823                continue;
     2824            }
    28222825
    28232826            if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
    28242827                $parsed = wp_parse_url( $url );
    28252828                if ( empty( $parsed['host'] ) ) {
     2829                    unset( $urls[ $key ] );
    28262830                    continue;
    28272831                }
    28282832
    2829                 if ( ! empty( $parsed['scheme'] ) ) {
     2833                if ( 'dns-prefetch' === $relation_type ) {
     2834                    $url = '//' . $parsed['host'];
     2835                } else if ( ! empty( $parsed['scheme'] ) ) {
    28302836                    $url = $parsed['scheme'] . '://' . $parsed['host'];
    28312837                } else {
     
    28342840            }
    28352841
    2836             printf( "<link rel='%s' href='%s'>\r\n", $relation_type, $url );
     2842            $urls[ $key ] = $url;
     2843        }
     2844
     2845        $urls = array_unique( $urls );
     2846
     2847        foreach ( $urls as $url ) {
     2848            printf( "<link rel='%s' href='%s'>\n", $relation_type, $url );
    28372849        }
    28382850    }
Note: See TracChangeset for help on using the changeset viewer.