diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
index 4f2be9f..cef554c 100644
|
|
|
function wp_resource_hints() { |
| 2815 | 2815 | * @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. |
| 2816 | 2816 | */ |
| 2817 | 2817 | $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); |
| 2818 | | $urls = array_unique( $urls ); |
| 2819 | 2818 | |
| 2820 | | foreach ( $urls as $url ) { |
| | 2819 | foreach ( $urls as $key => $url ) { |
| 2821 | 2820 | $url = esc_url( $url, array( 'http', 'https' ) ); |
| 2822 | 2821 | |
| 2823 | 2822 | if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { |
| … |
… |
function wp_resource_hints() { |
| 2826 | 2825 | continue; |
| 2827 | 2826 | } |
| 2828 | 2827 | |
| 2829 | | if ( ! empty( $parsed['scheme'] ) ) { |
| | 2828 | if ( 'dns-prefetch' === $relation_type ) { |
| | 2829 | $url = '//' . $parsed['host']; |
| | 2830 | } else if ( ! empty( $parsed['scheme'] ) ) { |
| 2830 | 2831 | $url = $parsed['scheme'] . '://' . $parsed['host']; |
| 2831 | 2832 | } else { |
| 2832 | 2833 | $url = $parsed['host']; |
| 2833 | 2834 | } |
| 2834 | 2835 | } |
| 2835 | 2836 | |
| 2836 | | printf( "<link rel='%s' href='%s'>\r\n", $relation_type, $url ); |
| | 2837 | $urls[ $key ] = $url; |
| | 2838 | } |
| | 2839 | |
| | 2840 | $urls = array_unique( $urls ); |
| | 2841 | |
| | 2842 | foreach ( $urls as $url ) { |
| | 2843 | printf( "<link rel='%s' href='%s'>\n", $relation_type, $url ); |
| 2837 | 2844 | } |
| 2838 | 2845 | } |
| 2839 | 2846 | } |
diff --git tests/phpunit/tests/general/resourceHints.php tests/phpunit/tests/general/resourceHints.php
index 351e6df..f75e199 100644
|
|
|
class Tests_WP_Resource_Hints extends WP_UnitTestCase { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | function test_should_have_defaults_on_frontend() { |
| 34 | | $expected = "<link rel='preconnect' href='http://s.w.org'>\r\n"; |
| | 34 | $expected = "<link rel='preconnect' href='http://s.w.org'>\n"; |
| 35 | 35 | |
| 36 | 36 | $this->expectOutputString( $expected ); |
| 37 | 37 | |
| … |
… |
class Tests_WP_Resource_Hints extends WP_UnitTestCase { |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function test_dns_prefetching() { |
| 42 | | $expected = "<link rel='dns-prefetch' href='http://wordpress.org'>\r\n" . |
| 43 | | "<link rel='dns-prefetch' href='https://google.com'>\r\n" . |
| 44 | | "<link rel='dns-prefetch' href='make.wordpress.org'>\r\n" . |
| 45 | | "<link rel='preconnect' href='http://s.w.org'>\r\n"; |
| | 42 | $expected = "<link rel='dns-prefetch' href='//wordpress.org'>\n" . |
| | 43 | "<link rel='dns-prefetch' href='//google.com'>\n" . |
| | 44 | "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" . |
| | 45 | "<link rel='preconnect' href='http://s.w.org'>\n"; |
| 46 | 46 | |
| 47 | 47 | add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 ); |
| 48 | 48 | |
| … |
… |
class Tests_WP_Resource_Hints extends WP_UnitTestCase { |
| 56 | 56 | function _add_dns_prefetch_domains( $hints, $method ) { |
| 57 | 57 | if ( 'dns-prefetch' === $method ) { |
| 58 | 58 | $hints[] = 'http://wordpress.org'; |
| | 59 | $hints[] = 'https://wordpress.org'; |
| 59 | 60 | $hints[] = 'https://google.com'; |
| 60 | 61 | $hints[] = '//make.wordpress.org'; |
| | 62 | $hints[] = 'https://wordpress.org/plugins/'; |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | return $hints; |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | function test_prerender() { |
| 67 | | $expected = "<link rel='preconnect' href='http://s.w.org'>\r\n" . |
| 68 | | "<link rel='prerender' href='https://make.wordpress.org/great-again'>\r\n" . |
| 69 | | "<link rel='prerender' href='http://jobs.wordpress.net'>\r\n" . |
| 70 | | "<link rel='prerender' href='//core.trac.wordpress.org'>\r\n"; |
| | 69 | $expected = "<link rel='preconnect' href='http://s.w.org'>\n" . |
| | 70 | "<link rel='prerender' href='https://make.wordpress.org/great-again'>\n" . |
| | 71 | "<link rel='prerender' href='http://jobs.wordpress.net'>\n" . |
| | 72 | "<link rel='prerender' href='//core.trac.wordpress.org'>\n"; |
| 71 | 73 | |
| 72 | 74 | add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 ); |
| 73 | 75 | |
| … |
… |
class Tests_WP_Resource_Hints extends WP_UnitTestCase { |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | function test_parse_url_dns_prefetch() { |
| 92 | | $expected = "<link rel='dns-prefetch' href='http://make.wordpress.org'>\r\n" . |
| 93 | | "<link rel='preconnect' href='http://s.w.org'>\r\n"; |
| | 94 | $expected = "<link rel='dns-prefetch' href='//make.wordpress.org'>\n" . |
| | 95 | "<link rel='preconnect' href='http://s.w.org'>\n"; |
| 94 | 96 | |
| 95 | 97 | add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 ); |
| 96 | 98 | |
| … |
… |
class Tests_WP_Resource_Hints extends WP_UnitTestCase { |
| 110 | 112 | } |
| 111 | 113 | |
| 112 | 114 | function test_dns_prefetch_styles() { |
| 113 | | $expected = "<link rel='dns-prefetch' href='http://fonts.googleapis.com'>\r\n" . |
| 114 | | "<link rel='preconnect' href='http://s.w.org'>\r\n"; |
| | 115 | $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" . |
| | 116 | "<link rel='preconnect' href='http://s.w.org'>\n"; |
| 115 | 117 | |
| 116 | 118 | $args = array( |
| 117 | 119 | 'family' => 'Open+Sans:400', |
| … |
… |
class Tests_WP_Resource_Hints extends WP_UnitTestCase { |
| 129 | 131 | } |
| 130 | 132 | |
| 131 | 133 | function test_dns_prefetch_scripts() { |
| 132 | | $expected = "<link rel='dns-prefetch' href='http://fonts.googleapis.com'>\r\n" . |
| 133 | | "<link rel='preconnect' href='http://s.w.org'>\r\n"; |
| | 134 | $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com'>\n" . |
| | 135 | "<link rel='preconnect' href='http://s.w.org'>\n"; |
| 134 | 136 | |
| 135 | 137 | $args = array( |
| 136 | 138 | 'family' => 'Open+Sans:400', |