From 8db6c6c4efc2b7b7e8a0046a57d19ba6790a3e57 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Sun, 23 Oct 2016 01:56:32 +0000 Subject: [PATCH] Bundled theme: Add preconnect to fonts.gstatic.com in 2012-15 themes. Add preconnect hinting for `https://fonts.gstatic.com` in the bundled themes using Google fonts. WordPress versions 4.7+ include a crossorigin attribute, earlier versions will not. Props leobaiano, swissspidy, peterwilsoncc. Fixes #37171. Built from https://develop.svn.wordpress.org/trunk@38870 git-svn-id: http://core.svn.wordpress.org/trunk@38813 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-content/themes/twentyfifteen/functions.php | 25 +++++++++++++++++++ .../themes/twentyfourteen/functions.php | 25 +++++++++++++++++++ .../themes/twentythirteen/functions.php | 25 +++++++++++++++++++ wp-content/themes/twentytwelve/functions.php | 25 +++++++++++++++++++ wp-includes/version.php | 2 +- 5 files changed, 101 insertions(+), 1 deletion(-) diff --git a/wp-content/themes/twentyfifteen/functions.php b/wp-content/themes/twentyfifteen/functions.php index 1c382bf138..8ae7e1dacc 100644 --- a/wp-content/themes/twentyfifteen/functions.php +++ b/wp-content/themes/twentyfifteen/functions.php @@ -285,6 +285,31 @@ function twentyfifteen_scripts() { } add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' ); +/** + * Add preconnect for Google Fonts. + * + * @since Twenty Fifteen 1.7 + * + * @param array $urls URLs to print for resource hints. + * @param string $relation_type The relation type the URLs are printed. + * @return array URLs to print for resource hints. + */ +function twentyfifteen_resource_hints( $urls, $relation_type ) { + if ( wp_style_is( 'twentyfifteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) { + if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) { + $urls[] = array( + 'href' => 'https://fonts.gstatic.com', + 'crossorigin', + ); + } else { + $urls[] = 'https://fonts.gstatic.com'; + } + } + + return $urls; +} +add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 ); + /** * Add featured image as background image to post navigation elements. * diff --git a/wp-content/themes/twentyfourteen/functions.php b/wp-content/themes/twentyfourteen/functions.php index f85ef1ca62..74141dc39c 100644 --- a/wp-content/themes/twentyfourteen/functions.php +++ b/wp-content/themes/twentyfourteen/functions.php @@ -277,6 +277,31 @@ function twentyfourteen_admin_fonts() { } add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' ); +/** + * Add preconnect for Google Fonts. + * + * @since Twenty Fourteen 1.9 + * + * @param array $urls URLs to print for resource hints. + * @param string $relation_type The relation type the URLs are printed. + * @return array URLs to print for resource hints. + */ +function twentyfourteen_resource_hints( $urls, $relation_type ) { + if ( wp_style_is( 'twentyfourteen-lato', 'queue' ) && 'preconnect' === $relation_type ) { + if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) { + $urls[] = array( + 'href' => 'https://fonts.gstatic.com', + 'crossorigin', + ); + } else { + $urls[] = 'https://fonts.gstatic.com'; + } + } + + return $urls; +} +add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 ); + if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) : /** * Print the attached image with a link to the next attached image. diff --git a/wp-content/themes/twentythirteen/functions.php b/wp-content/themes/twentythirteen/functions.php index ae1bd9e33a..d1f7d5b482 100644 --- a/wp-content/themes/twentythirteen/functions.php +++ b/wp-content/themes/twentythirteen/functions.php @@ -190,6 +190,31 @@ function twentythirteen_scripts_styles() { } add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' ); +/** + * Add preconnect for Google Fonts. + * + * @since Twenty Thirteen 2.1 + * + * @param array $urls URLs to print for resource hints. + * @param string $relation_type The relation type the URLs are printed. + * @return array URLs to print for resource hints. + */ +function twentythirteen_resource_hints( $urls, $relation_type ) { + if ( wp_style_is( 'twentythirteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) { + if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) { + $urls[] = array( + 'href' => 'https://fonts.gstatic.com', + 'crossorigin', + ); + } else { + $urls[] = 'https://fonts.gstatic.com'; + } + } + + return $urls; +} +add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 ); + /** * Filter the page title. * diff --git a/wp-content/themes/twentytwelve/functions.php b/wp-content/themes/twentytwelve/functions.php index 56cd8e583b..2dc2cd8bd7 100644 --- a/wp-content/themes/twentytwelve/functions.php +++ b/wp-content/themes/twentytwelve/functions.php @@ -157,6 +157,31 @@ function twentytwelve_scripts_styles() { } add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); +/** + * Add preconnect for Google Fonts. + * + * @since Twenty Twelve 2.2 + * + * @param array $urls URLs to print for resource hints. + * @param string $relation_type The relation type the URLs are printed. + * @return array URLs to print for resource hints. + */ +function twentytwelve_resource_hints( $urls, $relation_type ) { + if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) && 'preconnect' === $relation_type ) { + if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) { + $urls[] = array( + 'href' => 'https://fonts.gstatic.com', + 'crossorigin', + ); + } else { + $urls[] = 'https://fonts.gstatic.com'; + } + } + + return $urls; +} +add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 ); + /** * Filter TinyMCE CSS path to include Google Fonts. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 314de738c4..6e1030b354 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38869'; +$wp_version = '4.7-alpha-38870'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.