Make WordPress Core

Changeset 55277


Ignore:
Timestamp:
02/07/2023 05:12:23 PM (16 months ago)
Author:
audrasjb
Message:

Twenty Twelve: Bundle Google Fonts locally.

This changeset bundles the Google Fonts used by Twenty Twelve locally in the theme folder, instead of loading them from Google servers. Existing font stylesheet handles are maintained for backward compatibilily.

Props garrett-eclipse, kjellr, ocean90, SergeyBiryukov, westonruter, luminuu, audrasjb, jhoffmann, jffng, paapst, cbirdsong, webcommsat, kau-boy, MatthiasReinholz, sabernhardt, hellofromTonya, JeffPaul, davidbaumwald, desrosj, bedas, poena, costdev, mukesh27, azaozz, aristath.
See #55985.

Location:
trunk/src/wp-content/themes/twentytwelve
Files:
40 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwelve/functions.php

    r55004 r55277  
    138138require get_template_directory() . '/inc/block-patterns.php';
    139139
    140 /**
    141  * Return the Google font stylesheet URL if available.
    142  *
    143  * The use of Open Sans by default is localized. For languages that use
    144  * characters not supported by the font, the font can be disabled.
    145  *
    146  * @since Twenty Twelve 1.2
    147  *
    148  * @return string Font stylesheet or empty string if disabled.
    149  */
    150 function twentytwelve_get_font_url() {
    151     $font_url = '';
    152 
    153     /*
    154      * translators: If there are characters in your language that are not supported
    155      * by Open Sans, translate this to 'off'. Do not translate into your own language.
    156      */
    157     if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
    158         $subsets = 'latin,latin-ext';
     140if ( ! function_exists( 'twentytwelve_get_font_url' ) ) :
     141    /**
     142     * Return the font stylesheet URL if available.
     143     *
     144     * The use of Open Sans by default is localized. For languages that use
     145     * characters not supported by the font, the font can be disabled.
     146     *
     147     * @since Twenty Twelve 1.2
     148     * @since Twenty Twelve 3.9 Replaced Google URL with self-hosted font.
     149     *
     150     * @return string Font stylesheet or empty string if disabled.
     151     */
     152    function twentytwelve_get_font_url() {
     153        $font_url = '';
    159154
    160155        /*
    161          * translators: To add an additional Open Sans character subset specific to your language,
    162          * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
    163          */
    164         $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
    165 
    166         if ( 'cyrillic' === $subset ) {
    167             $subsets .= ',cyrillic,cyrillic-ext';
    168         } elseif ( 'greek' === $subset ) {
    169             $subsets .= ',greek,greek-ext';
    170         } elseif ( 'vietnamese' === $subset ) {
    171             $subsets .= ',vietnamese';
     156        * translators: If there are characters in your language that are not supported
     157        * by Open Sans, translate this to 'off'. Do not translate into your own language.
     158        */
     159        if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
     160            $font_url = get_template_directory_uri() . '/fonts/font-open-sans.css';
    172161        }
    173162
    174         $query_args = array(
    175             'family'  => urlencode( 'Open Sans:400italic,700italic,400,700' ),
    176             'subset'  => urlencode( $subsets ),
    177             'display' => urlencode( 'fallback' ),
    178         );
    179         $font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    180     }
    181 
    182     return $font_url;
    183 }
     163        return $font_url;
     164    }
     165endif;
    184166
    185167/**
     
    204186    $font_url = twentytwelve_get_font_url();
    205187    if ( ! empty( $font_url ) ) {
    206         wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
     188        $font_version = ( 0 === strpos( (string) twentytwelve_get_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     189        wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), $font_version );
    207190    }
    208191
     
    228211    wp_enqueue_style( 'twentytwelve-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20200713' );
    229212    // Add custom fonts.
    230     wp_enqueue_style( 'twentytwelve-fonts', twentytwelve_get_font_url(), array(), null );
     213    $font_version = ( 0 === strpos( (string) twentytwelve_get_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     214    wp_enqueue_style( 'twentytwelve-fonts', twentytwelve_get_font_url(), array(), $font_version );
    231215}
    232216add_action( 'enqueue_block_editor_assets', 'twentytwelve_block_editor_styles' );
     
    236220 *
    237221 * @since Twenty Twelve 2.2
     222 * @deprecated Twenty Twelve 3.9 Disabled filter because, by default, fonts are self-hosted.
    238223 *
    239224 * @param array   $urls          URLs to print for resource hints.
     
    255240    return $urls;
    256241}
    257 add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 );
    258 
    259 /**
    260  * Filter TinyMCE CSS path to include Google Fonts.
     242// add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 );
     243
     244/**
     245 * Filter TinyMCE CSS path to include hosted fonts.
    261246 *
    262247 * Adds additional stylesheets to the TinyMCE editor if needed.
    263248 *
    264  * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
     249 * @uses twentytwelve_get_font_url() To get the font stylesheet URL.
    265250 *
    266251 * @since Twenty Twelve 1.2
  • trunk/src/wp-content/themes/twentytwelve/readme.txt

    r55024 r55277  
    4040Licenses: MIT/GPL2
    4141Source: https://github.com/aFarkas/html5shiv
     42
     43Open Sans Font
     44Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans)
     45License: SIL Open Font License, 1.1, https://opensource.org/licenses/OFL-1.1
     46Source: https://fontsource.org/fonts/open-sans
    4247
    4348"Fall Leaf Photo" by Tim Sullivan. CC0. https://stocksnap.io/photo/fall-leaf-ZBK0NLVP2B
Note: See TracChangeset for help on using the changeset viewer.