Make WordPress Core

Ticket #34292: 34292.2.diff

File 34292.2.diff, 4.1 KB (added by voldemortensen, 10 years ago)
  • src/wp-includes/default-filters.php

     
    235235add_action( 'wp_head',             'wp_print_head_scripts',            9    );
    236236add_action( 'wp_head',             'wp_generator'                           );
    237237add_action( 'wp_head',             'rel_canonical'                          );
     238add_action( 'wp_head',             'wp_prerender'                           );
     239add_action( 'wp_head',             'wp_dns_prefetch'                        );
    238240add_action( 'wp_head',             'wp_shortlink_wp_head',            10, 0 );
    239241add_action( 'wp_head',             'wp_site_icon',                    99    );
    240242add_action( 'wp_footer',           'wp_print_footer_scripts',         20    );
  • src/wp-includes/general-template.php

     
    27552755}
    27562756
    27572757/**
     2758 * Prints out URLs to be prerendered.
     2759 *
     2760 * @since 4.6.0
     2761 */
     2762function 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 = apply_filters( 'prerender_urls', array() );
     2771        $prerender_urls = array_unique( array_map( 'strtolower', $prerender_urls ) );
     2772
     2773        foreach ( $prerender_urls as $url ) {
     2774                $url = esc_url( $url, array( 'http', 'https' ) );
     2775                printf( "<link rel='prerender' href='%s'>\r\n", $url );
     2776        }
     2777}
     2778
     2779/**
     2780 * Prints out domains to prefetch for page speed optimization.
     2781 *
     2782 * @since 4.6.0
     2783 */
     2784function wp_dns_prefetch() {
     2785        /**
     2786         * Filter the domains to prefetch for page speed optimization.
     2787         *
     2788         * @since 4.6.0
     2789         *
     2790         * @param array $prefetch_urls Domains to prefetch.
     2791         */
     2792        $prefetch_domains = apply_filters( 'dns_prefetch_domains', array() );
     2793        $prefetch_domains = array_unique( array_map( 'strtolower', $prefetch_domains ) );
     2794
     2795        foreach ( $prefetch_domains as $domain ) {
     2796                $domain = esc_url( untrailingslashit( $domain ), array( 'http', 'https' ) );
     2797                printf( "<link rel='dns-prefetch' href='%s'>\r\n", $domain );
     2798        }
     2799}
     2800
     2801/**
    27582802 * Whether the user should have a WYSIWIG editor.
    27592803 *
    27602804 * Checks that the user requires a WYSIWIG editor and that the editor is
  • tests/phpunit/tests/general/template.php

     
    345345                $this->custom_logo_id  = $this->_make_attachment( $upload );
    346346                return $this->custom_logo_id;
    347347        }
     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        }
    348394}