Make WordPress Core

Ticket #34292: 34292.10.diff

File 34292.10.diff, 2.2 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/general-template.php

    diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
    index 4f2be9f..df0cdd0 100644
    function wp_site_icon() { 
    27992799 */
    28002800function wp_resource_hints() {
    28012801        $hints = array(
    2802                 'dns-prefetch' => wp_resource_hints_scripts_styles(),
     2802                'dns-prefetch' => wp_dependencies_unique_hosts(),
    28032803                'preconnect'   => array( 's.w.org' ),
    28042804                'prefetch'     => array(),
    28052805                'prerender'    => array(),
    function wp_resource_hints() { 
    28392839}
    28402840
    28412841/**
    2842  * Adds dns-prefetch for all scripts and styles enqueued from external hosts.
     2842 * Returns a list of unique hosts of all enqueued scripts and styles.
    28432843 *
    28442844 * @since 4.6.0
     2845 *
     2846 * @return array A list of unique hosts of enqueued scripts and styles.
    28452847 */
    2846 function wp_resource_hints_scripts_styles() {
     2848function wp_dependencies_unique_hosts() {
    28472849        global $wp_scripts, $wp_styles;
    28482850
    28492851        $unique_hosts = array();
    28502852
    2851         if ( is_object( $wp_scripts ) && ! empty( $wp_scripts->registered ) ) {
    2852                 foreach ( $wp_scripts->registered as $registered_script ) {
    2853                         $parsed = wp_parse_url( $registered_script->src );
     2853        foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
     2854                if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
     2855                        foreach ( $dependencies->queue as $handle ) {
     2856                                /* @var _WP_Dependency $dependency */
     2857                                $dependency = $dependencies->registered[ $handle ];
     2858                                $parsed     = wp_parse_url( $dependency->src );
    28542859
    2855                         if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) {
    2856                                 $unique_hosts[] = $parsed['host'];
    2857                         }
    2858                 }
    2859         }
    2860 
    2861         if ( is_object( $wp_styles ) && ! empty( $wp_styles->registered ) ) {
    2862                 foreach ( $wp_styles->registered as $registered_style ) {
    2863                         $parsed = wp_parse_url( $registered_style->src );
    2864 
    2865                         if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) {
    2866                                 $unique_hosts[] = $parsed['host'];
     2860                                if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) {
     2861                                        $unique_hosts[] = $parsed['host'];
     2862                                }
    28672863                        }
    28682864                }
    28692865        }