Make WordPress Core

Ticket #44302: 44302.diff

File 44302.diff, 4.0 KB (added by swissspidy, 7 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index 5487c8fbe4..c3b07e487b 100644
    add_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 ); 
    268268// Actions
    269269add_action( 'wp_head', '_wp_render_title_tag', 1 );
    270270add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
     271add_action( 'template_redirect', 'wp_dns_prefetch_control_header', 11, 0 );
    271272add_action( 'wp_head', 'wp_resource_hints', 2 );
    272273add_action( 'wp_head', 'feed_links', 2 );
    273274add_action( 'wp_head', 'feed_links_extra', 3 );
  • src/wp-includes/general-template.php

    diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
    index 57a7b675dc..92d082b08f 100644
    function wp_site_icon() { 
    29132913}
    29142914
    29152915/**
    2916  * Prints resource hints to browsers for pre-fetching, pre-rendering
    2917  * and pre-connecting to web sites.
     2916 * Returns the unique list of URLs and hosts that can be used for resource hints.
    29182917 *
    2919  * Gives hints to browsers to prefetch specific pages or render them
     2918 * Resource hints suggest browsers to prefetch specific pages or render them
    29202919 * in the background, to perform DNS lookups or to begin the connection
    29212920 * handshake (DNS, TCP, TLS) in the background.
    29222921 *
    2923  * These performance improving indicators work by using `<link rel"…">`.
    2924  *
    2925  * @since 4.6.0
     2922 * @since 5.0.0
    29262923 */
    2927 function wp_resource_hints() {
     2924function wp_get_resource_hints() {
    29282925        $hints = array(
    29292926                'dns-prefetch' => wp_dependencies_unique_hosts(),
    29302927                'preconnect'   => array(),
    function wp_resource_hints() { 
    29952992                        $unique_urls[ $url ] = $atts;
    29962993                }
    29972994
    2998                 foreach ( $unique_urls as $atts ) {
    2999                         $html = '';
     2995                return $unique_urls;
     2996        }
     2997}
    30002998
    3001                         foreach ( $atts as $attr => $value ) {
    3002                                 if ( ! is_scalar( $value ) ||
    3003                                         ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) ) ) {
     2999/**
     3000 * Sends an X-DNS-Prefetch-Control response header.
     3001 *
     3002 * By default, the header is only sent if dns-prefetch resource hints are added.
     3003 *
     3004 * @since 5.0.0
     3005 */
     3006function wp_dns_prefetch_control_header() {
     3007        $unique_urls = wp_get_resource_hints();
    30043008
    3005                                         continue;
    3006                                 }
     3009        /**
     3010         * Filters whether WordPress should send an X-DNS-Prefetch-Control header.
     3011         *
     3012         * @since 5.0.0
     3013         *
     3014         * @param bool $send_header Whether the header should be sent or not.
     3015         *                          True if dns-prefetch resource hints are added, false otherwise.
     3016         */
     3017        $send_header = apply_filters( 'dns_prefetch_control_header', ! empty( $unique_urls['dns-prefetch'] ) );
    30073018
    3008                                 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
     3019        if (!$send_header) {
     3020                return;
     3021        }
    30093022
    3010                                 if ( ! is_string( $attr ) ) {
    3011                                         $html .= " $value";
    3012                                 } else {
    3013                                         $html .= " $attr='$value'";
    3014                                 }
     3023        header( 'X-DNS-Prefetch-Control: on', false );
     3024}
     3025
     3026/**
     3027 * Prints resource hints to browsers for pre-fetching, pre-rendering
     3028 * and pre-connecting to web sites.
     3029 *
     3030 * Gives hints to browsers to prefetch specific pages or render them
     3031 * in the background, to perform DNS lookups or to begin the connection
     3032 * handshake (DNS, TCP, TLS) in the background.
     3033 *
     3034 * These performance improving indicators work by using `<link rel"…">`.
     3035 *
     3036 * @since 4.6.0
     3037 */
     3038function wp_resource_hints() {
     3039        $unique_urls = wp_get_resource_hints();
     3040
     3041        foreach ( $unique_urls as $atts ) {
     3042                $html = '';
     3043
     3044                foreach ( $atts as $attr => $value ) {
     3045                        if ( ! is_scalar( $value ) ||
     3046                                ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) ) ) {
     3047
     3048                                continue;
    30153049                        }
    30163050
    3017                         $html = trim( $html );
     3051                        $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
    30183052
    3019                         echo "<link $html />\n";
     3053                        if ( ! is_string( $attr ) ) {
     3054                                $html .= " $value";
     3055                        } else {
     3056                                $html .= " $attr='$value'";
     3057                        }
    30203058                }
     3059
     3060                $html = trim( $html );
     3061
     3062                echo "<link $html />\n";
    30213063        }
    30223064}
    30233065