Make WordPress Core

Changeset 55274


Ignore:
Timestamp:
02/07/2023 04:43:48 PM (16 months ago)
Author:
audrasjb
Message:

Twenty Thirteen: Bundle Google Fonts locally.

This changeset bundles the Google Fonts used by Twenty Thirteen 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/twentythirteen
Files:
68 added
2 edited

Legend:

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

    r55004 r55274  
    8181    /*
    8282     * This theme styles the visual editor to resemble the theme style,
    83      * specifically font, colors, icons, and column width.
    84      */
    85     add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentythirteen_fonts_url() ) );
     83     * specifically font, colors, icons, and column width. When fonts are
     84     * self-hosted, the theme directory needs to be removed first.
     85     */
     86    $font_stylesheet = str_replace(
     87        array( get_template_directory_uri() . '/', get_stylesheet_directory_uri() . '/' ),
     88        '',
     89        twentythirteen_fonts_url()
     90    );
     91    add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', $font_stylesheet ) );
    8692
    8793    // Load regular editor styles into the new block-based editor.
     
    244250add_action( 'after_setup_theme', 'twentythirteen_setup' );
    245251
    246 /**
    247  * Return the Google font stylesheet URL, if available.
    248  *
    249  * The use of Source Sans Pro and Bitter by default is localized. For languages
    250  * that use characters not supported by the font, the font can be disabled.
    251  *
    252  * @since Twenty Thirteen 1.0
    253  *
    254  * @return string Font stylesheet or empty string if disabled.
    255  */
    256 function twentythirteen_fonts_url() {
    257     $fonts_url = '';
    258 
    259     /*
    260      * translators: If there are characters in your language that are not supported
    261      * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
    262      */
    263     $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'twentythirteen' );
    264 
    265     /*
    266      * translators: If there are characters in your language that are not supported
    267      * by Bitter, translate this to 'off'. Do not translate into your own language.
    268      */
    269     $bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' );
    270 
    271     if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
    272         $font_families = array();
    273 
    274         if ( 'off' !== $source_sans_pro ) {
    275             $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
    276         }
    277 
    278         if ( 'off' !== $bitter ) {
    279             $font_families[] = 'Bitter:400,700';
    280         }
    281 
    282         $query_args = array(
    283             'family'  => urlencode( implode( '|', $font_families ) ),
    284             'subset'  => urlencode( 'latin,latin-ext' ),
    285             'display' => urlencode( 'fallback' ),
    286         );
    287         $fonts_url  = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    288     }
    289 
    290     return $fonts_url;
    291 }
     252if ( ! function_exists( 'twentythirteen_fonts_url' ) ) :
     253    /**
     254     * Return the font stylesheet URL, if available.
     255     *
     256     * The use of Source Sans Pro and Bitter by default is localized. For languages
     257     * that use characters not supported by the font, the font can be disabled.
     258     *
     259     * @since Twenty Thirteen 1.0
     260     * @since Twenty Thirteen 3.8 Replaced Google URL with self-hosted fonts.
     261     *
     262     * @return string Font stylesheet or empty string if disabled.
     263     */
     264    function twentythirteen_fonts_url() {
     265        $fonts_url = '';
     266
     267        /*
     268         * translators: If there are characters in your language that are not supported
     269         * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
     270         */
     271        $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'twentythirteen' );
     272
     273        /*
     274         * translators: If there are characters in your language that are not supported
     275         * by Bitter, translate this to 'off'. Do not translate into your own language.
     276         */
     277        $bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' );
     278
     279        if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
     280            $font_families = array();
     281
     282            if ( 'off' !== $source_sans_pro ) {
     283                $font_families[] = 'source-sans-pro';
     284            }
     285
     286            if ( 'off' !== $bitter ) {
     287                $font_families[] = 'bitter';
     288            }
     289
     290            $fonts_url = get_template_directory_uri() . '/fonts/' . implode( '-plus-', $font_families ) . '.css';
     291        }
     292
     293        return $fonts_url;
     294    }
     295endif;
    292296
    293297/**
     
    314318
    315319    // Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
    316     wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
     320    $font_version = ( 0 === strpos( (string) twentythirteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     321    wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), $font_version );
    317322
    318323    // Add Genericons font, used in the main stylesheet.
     
    335340 *
    336341 * @since Twenty Thirteen 2.1
     342 * @deprecated Twenty Thirteen 3.8 Disabled filter because, by default, fonts are self-hosted.
    337343 *
    338344 * @param array   $urls          URLs to print for resource hints.
     
    354360    return $urls;
    355361}
    356 add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
     362// add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
    357363
    358364/**
     
    365371    wp_enqueue_style( 'twentythirteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20210621' );
    366372    // Add custom fonts.
    367     wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
     373    $font_version = ( 0 === strpos( (string) twentythirteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     374    wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), $font_version );
    368375}
    369376add_action( 'enqueue_block_editor_assets', 'twentythirteen_block_editor_styles' );
  • trunk/src/wp-content/themes/twentythirteen/readme.txt

    r55024 r55274  
    4545Source: http://www.genericons.com
    4646
     47Bitter Font
     48Copyright 2011 The Bitter Project Authors (https://github.com/solmatas/BitterPro)
     49License: SIL Open Font License, 1.1, https://opensource.org/licenses/OFL-1.1
     50Source: https://fontsource.org/fonts/bitter
     51
     52Source Sans Pro Font
     53© 2010 - 2018 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name ‘Source’.
     54License: SIL Open Font License, 1.1, https://opensource.org/licenses/OFL-1.1
     55Source: https://fontsource.org/fonts/source-sans-pro
     56
    4757Images
    4858Cylinder Interior: https://www.flickr.com/photos/nasacommons/14052998066/in/album-72157644439092941/. Rick Guidice, NASA Ames Research Center.
Note: See TracChangeset for help on using the changeset viewer.