Ticket #34292: 34292.3.diff
| File 34292.3.diff, 4.8 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/default-filters.php
235 235 add_action( 'wp_head', 'wp_print_head_scripts', 9 ); 236 236 add_action( 'wp_head', 'wp_generator' ); 237 237 add_action( 'wp_head', 'rel_canonical' ); 238 add_action( 'wp_head', 'wp_prerender' ); 239 add_action( 'wp_head', 'wp_dns_prefetch' ); 238 240 add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); 239 241 add_action( 'wp_head', 'wp_site_icon', 99 ); 240 242 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 ); -
src/wp-includes/general-template.php
2755 2755 } 2756 2756 2757 2757 /** 2758 * Prints out URLs to be prerendered. 2759 * 2760 * @since 4.6.0 2761 */ 2762 function wp_prerender() { 2763 /** 2764 * Filter which URLs to prerender. 2765 * 2766 * @since 4.6.0 2767 * 2768 * @param array $prerender_urls URLs to prerender. 2769 */ 2770 $prerender_urls = wp_prerender_posts(); 2771 $prerender_urls = apply_filters( 'prerender_urls', $prerender_urls ); 2772 $prerender_urls = array_unique( array_map( 'strtolower', $prerender_urls ) ); 2773 2774 foreach ( $prerender_urls as $url ) { 2775 $url = esc_url( $url, array( 'http', 'https' ) ); 2776 printf( "<link rel='prerender' href='%s'>\r\n", $url ); 2777 } 2778 } 2779 2780 /** 2781 * Adds posts to be prerendered. 2782 * 2783 * @since 4.6.0 2784 */ 2785 function wp_prerender_posts() { 2786 $posts_to_prerender = array(); 2787 2788 if ( is_home() ) { 2789 2790 while( have_posts() ) { 2791 the_post(); 2792 array_push( $posts_to_prerender, get_the_permalink() ); 2793 } 2794 2795 rewind_posts(); 2796 2797 } elseif ( is_single() ) { 2798 2799 $next_post = get_next_post(); 2800 $previous_post = get_previous_post(); 2801 2802 if ( ! empty( $next_post ) ) { 2803 array_push( $posts_to_prerender, get_permalink( $next_post->ID ) ); 2804 } 2805 2806 if ( ! empty( $previous_post ) ) { 2807 array_push( $posts_to_prerender, get_permalink( $previous_post->ID ) ); 2808 } 2809 2810 } 2811 2812 return $posts_to_prerender; 2813 } 2814 2815 /** 2816 * Prints out domains to prefetch for page speed optimization. 2817 * 2818 * @since 4.6.0 2819 */ 2820 function wp_dns_prefetch() { 2821 /** 2822 * Filter the domains to prefetch for page speed optimization. 2823 * 2824 * @since 4.6.0 2825 * 2826 * @param array $prefetch_urls Domains to prefetch. 2827 */ 2828 $prefetch_domains = apply_filters( 'dns_prefetch_domains', array() ); 2829 $prefetch_domains = array_unique( array_map( 'strtolower', $prefetch_domains ) ); 2830 2831 foreach ( $prefetch_domains as $domain ) { 2832 $domain = esc_url( untrailingslashit( $domain ), array( 'http', 'https' ) ); 2833 printf( "<link rel='dns-prefetch' href='%s'>\r\n", $domain ); 2834 } 2835 } 2836 2837 /** 2758 2838 * Whether the user should have a WYSIWIG editor. 2759 2839 * 2760 2840 * Checks that the user requires a WYSIWIG editor and that the editor is -
tests/phpunit/tests/general/template.php
345 345 $this->custom_logo_id = $this->_make_attachment( $upload ); 346 346 return $this->custom_logo_id; 347 347 } 348 349 /** 350 * @ticket 34292 351 */ 352 function test_wp_dns_prefetch() { 353 $this->assertEmpty( get_echo( 'wp_dns_prefetch' ) ); 354 355 add_filter( 'dns_prefetch_domains', array( $this, '_add_dns_prefetch_domains' ) ); 356 357 $expected = "<link rel='dns-prefetch' href='http://wordpress.org'>\r\n" . 358 "<link rel='dns-prefetch' href='https://google.com'>\r\n" . 359 "<link rel='dns-prefetch' href='//make.wordpress.org'>\r\n"; 360 361 $this->assertEquals( $expected, get_echo( 'wp_dns_prefetch' ) ); 362 } 363 364 function _add_dns_prefetch_domains( $domains ) { 365 $domains[] = 'http://wordpress.org'; 366 $domains[] = 'https://google.com'; 367 $domains[] = '//make.wordpress.org'; 368 369 return $domains; 370 } 371 372 /** 373 * @ticket 34292 374 */ 375 function test_wp_prerender() { 376 $this->assertEmpty( get_echo( 'wp_prerender' ) ); 377 378 add_filter( 'prerender_urls', array( $this, '_add_prerender_urls' ) ); 379 380 $expected = "<link rel='prerender' href='https://make.wordpress.org/great-again'>\r\n" . 381 "<link rel='prerender' href='http://jobs.wordpress.net'>\r\n" . 382 "<link rel='prerender' href='//core.trac.wordpress.org'>\r\n"; 383 384 $this->assertEquals( $expected, get_echo( 'wp_prerender' ) ); 385 } 386 387 function _add_prerender_urls( $urls ) { 388 $urls[] = 'https://make.wordpress.org/great-again'; 389 $urls[] = 'http://jobs.wordpress.net'; 390 $urls[] = '//core.trac.wordpress.org'; 391 392 return $urls; 393 } 348 394 }