Changeset 37920
- Timestamp:
- 06/29/2016 07:35:27 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/admin-filters.php
r37619 r37920 43 43 add_action( 'admin_head', 'wp_site_icon' ); 44 44 add_action( 'admin_head', '_ipad_meta' ); 45 46 // Prerendering. 47 add_filter( 'admin_head', 'wp_resource_hints' ); 45 48 46 49 add_action( 'admin_print_scripts-post.php', 'wp_page_reload_on_back_button_js' ); -
trunk/src/wp-includes/default-filters.php
r37915 r37920 240 240 add_action( 'wp_head', 'wp_generator' ); 241 241 add_action( 'wp_head', 'rel_canonical' ); 242 add_action( 'wp_head', 'wp_resource_hints' ); 242 243 add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); 243 244 add_action( 'wp_head', 'wp_site_icon', 99 ); -
trunk/src/wp-includes/general-template.php
r37866 r37920 2789 2789 2790 2790 /** 2791 * Prints resource hints to browsers for pre-fetching, pre-rendering and pre-connecting to web sites. 2792 * 2793 * Gives hints to browsers to prefetch specific pages or render them in the background, 2794 * to perform DNS lookups or to begin the connection handshake (DNS, TCP, TLS) in the background. 2795 * 2796 * These performance improving indicators work by using `<link rel"…">`. 2797 * 2798 * @since 4.6.0 2799 */ 2800 function wp_resource_hints() { 2801 $hints = array( 2802 'dns-prefetch' => wp_resource_hints_scripts_styles(), 2803 'preconnect' => array( 's.w.org' ), 2804 'prefetch' => array(), 2805 'prerender' => array(), 2806 ); 2807 2808 foreach ( $hints as $relation_type => $urls ) { 2809 /** 2810 * Filters domains and URLs for resource hints. 2811 * 2812 * @since 4.6.0 2813 * 2814 * @param array $urls URLs to print for resource hints. 2815 * @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. 2816 */ 2817 $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); 2818 $urls = array_unique( $urls ); 2819 2820 foreach ( $urls as $url ) { 2821 $url = esc_url( $url, array( 'http', 'https' ) ); 2822 2823 if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { 2824 $parsed = parse_url( $url ); 2825 2826 if ( ! empty( $parsed['scheme'] ) ) { 2827 $url = $parsed['scheme'] . '://' . $parsed['host']; 2828 } else { 2829 $url = $parsed['host']; 2830 } 2831 } 2832 2833 printf( "<link rel='%s' href='%s'>\r\n", $relation_type, $url ); 2834 } 2835 } 2836 } 2837 2838 /** 2839 * Adds dns-prefetch for all scripts and styles enqueued from external hosts. 2840 * 2841 * @since 4.6.0 2842 */ 2843 function wp_resource_hints_scripts_styles() { 2844 global $wp_scripts, $wp_styles; 2845 2846 $unique_hosts = array(); 2847 2848 if ( is_object( $wp_scripts ) && ! empty( $wp_scripts->registered ) ) { 2849 foreach ( $wp_scripts->registered as $registered_script ) { 2850 $src = $registered_script->src; 2851 // Make sure the URL has a scheme, otherwise parse_url() could fail to pass the host. 2852 if ( '//' == substr( $src, 0, 2 ) ) { 2853 $src = set_url_scheme( $src ); 2854 } 2855 2856 $this_host = parse_url( $src, PHP_URL_HOST ); 2857 if ( ! empty( $this_host ) && ! in_array( $this_host, $unique_hosts ) && $this_host !== $_SERVER['SERVER_NAME'] ) { 2858 $unique_hosts[] = $this_host; 2859 } 2860 } 2861 } 2862 2863 if ( is_object( $wp_styles ) && ! empty( $wp_styles->registered ) ) { 2864 foreach ( $wp_styles->registered as $registered_style ) { 2865 $src = $registered_style->src; 2866 // Make sure the URL has a scheme, otherwise parse_url() could fail to pass the host. 2867 if ( '//' == substr( $src, 0, 2 ) ) { 2868 $src = set_url_scheme( $src ); 2869 } 2870 2871 $this_host = parse_url( $src, PHP_URL_HOST ); 2872 if ( ! empty( $this_host ) && ! in_array( $this_host, $unique_hosts ) && $this_host !== $_SERVER['SERVER_NAME'] ) { 2873 $unique_hosts[] = $this_host; 2874 } 2875 } 2876 } 2877 2878 return $unique_hosts; 2879 } 2880 2881 /** 2791 2882 * Whether the user should have a WYSIWIG editor. 2792 2883 *
Note: See TracChangeset
for help on using the changeset viewer.