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:
parent
f160f2afd1
commit
e5f967ca99
|
@ -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'.
|
* @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 = 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' ) );
|
$url = esc_url( $url, array( 'http', 'https' ) );
|
||||||
|
if ( ! $url ) {
|
||||||
|
unset( $urls[ $key ] );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
|
if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
|
||||||
$parsed = wp_parse_url( $url );
|
$parsed = wp_parse_url( $url );
|
||||||
if ( empty( $parsed['host'] ) ) {
|
if ( empty( $parsed['host'] ) ) {
|
||||||
|
unset( $urls[ $key ] );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $parsed['scheme'] ) ) {
|
if ( 'dns-prefetch' === $relation_type ) {
|
||||||
|
$url = '//' . $parsed['host'];
|
||||||
|
} else if ( ! empty( $parsed['scheme'] ) ) {
|
||||||
$url = $parsed['scheme'] . '://' . $parsed['host'];
|
$url = $parsed['scheme'] . '://' . $parsed['host'];
|
||||||
} else {
|
} else {
|
||||||
$url = $parsed['host'];
|
$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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue