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.
Built from https://develop.svn.wordpress.org/trunk@38036


git-svn-id: http://core.svn.wordpress.org/trunk@37977 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-07-12 11:32:28 +00:00
parent f160f2afd1
commit e5f967ca99
2 changed files with 17 additions and 5 deletions

View File

@ -2815,25 +2815,37 @@ function wp_resource_hints() {
* @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'.
*/
$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
$urls = array_unique( $urls );
foreach ( $urls as $url ) {
foreach ( $urls as $key => $url ) {
$url = esc_url( $url, array( 'http', 'https' ) );
if ( ! $url ) {
unset( $urls[ $key ] );
continue;
}
if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
$parsed = wp_parse_url( $url );
if ( empty( $parsed['host'] ) ) {
unset( $urls[ $key ] );
continue;
}
if ( ! empty( $parsed['scheme'] ) ) {
if ( 'dns-prefetch' === $relation_type ) {
$url = '//' . $parsed['host'];
} else if ( ! empty( $parsed['scheme'] ) ) {
$url = $parsed['scheme'] . '://' . $parsed['host'];
} else {
$url = $parsed['host'];
}
}
printf( "<link rel='%s' href='%s'>\r\n", $relation_type, $url );
$urls[ $key ] = $url;
}
$urls = array_unique( $urls );
foreach ( $urls as $url ) {
printf( "<link rel='%s' href='%s'>\n", $relation_type, $url );
}
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-beta2-38035';
$wp_version = '4.6-beta2-38036';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.