Make WordPress Core

Ticket #34292: 34292.diff

File 34292.diff, 3.0 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index 75dadfc..ae0f9cd 100644
    add_action( 'wp_head', 'wp_print_styles', 8 ); 
    233233add_action( 'wp_head',             'wp_print_head_scripts',            9    );
    234234add_action( 'wp_head',             'wp_generator'                           );
    235235add_action( 'wp_head',             'rel_canonical'                          );
     236add_action( 'wp_head',             'wp_dns_prefetch'                        );
    236237add_action( 'wp_head',             'wp_shortlink_wp_head',            10, 0 );
    237238add_action( 'wp_head',             'wp_site_icon',                    99    );
    238239add_action( 'wp_footer',           'wp_print_footer_scripts',         20    );
  • src/wp-includes/general-template.php

    diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
    index 23525b5..8ec9629 100644
    function wp_site_icon() { 
    25232523}
    25242524
    25252525/**
     2526 * Prints out domains to prefetch for page speed optimization.
     2527 *
     2528 * @since 4.4.0
     2529 */
     2530function wp_dns_prefetch() {
     2531        /**
     2532         * Filter the domains to prefetch for page speed optimization.
     2533         *
     2534         * @since 4.4.0
     2535         *
     2536         * @param array $prefetch_urls Domains to prefetch.
     2537         */
     2538        $prefetch_domains = apply_filters( 'dns_prefetch_domains', array() );
     2539        $prefetch_domains = array_unique( array_map( 'strtolower', $prefetch_domains ) );
     2540
     2541        foreach ( $prefetch_domains as $domain ) {
     2542                $domain = esc_url( untrailingslashit( $domain ), array('http', 'https') );
     2543                printf( "<link rel='dns-prefetch' href='%s'>\r\n", $domain );
     2544        }
     2545}
     2546
     2547/**
    25262548 * Whether the user should have a WYSIWIG editor.
    25272549 *
    25282550 * Checks that the user requires a WYSIWIG editor and that the editor is
  • tests/phpunit/tests/general/template.php

    diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php
    index f935a1b..39a935c 100644
    class Tests_General_Template extends WP_UnitTestCase { 
    177177                $this->site_icon_id  = wp_insert_attachment( $attachment, $upload['file'] );
    178178                wp_update_attachment_metadata( $this->site_icon_id, wp_generate_attachment_metadata( $this->site_icon_id, $upload['file'] ) );
    179179        }
     180
     181        /**
     182         * @ticket 34292
     183         */
     184        function test_wp_dns_prefetch() {
     185                $this->assertEmpty( get_echo( 'wp_dns_prefetch' ) );
     186
     187                add_filter( 'dns_prefetch_domains', array( $this, '_add_dns_prefetch_domains' ) );
     188
     189                $expected = "<link rel='dns-prefetch' href='http://wordpress.org'>\r\n" .
     190                            "<link rel='dns-prefetch' href='https://google.com'>\r\n" .
     191                            "<link rel='dns-prefetch' href='//make.wordpress.org'>\r\n";
     192
     193                $this->assertEquals( $expected, get_echo( 'wp_dns_prefetch' ) );
     194        }
     195
     196        function _add_dns_prefetch_domains( $domains ) {
     197                $domains[] = 'http://wordpress.org';
     198                $domains[] = 'https://google.com';
     199                $domains[] = '//make.wordpress.org';
     200
     201                return $domains;
     202        }
    180203}