Make WordPress Core

Changeset 55268

Timestamp:
02/07/2023 03:50:14 PM (18 months ago)
Author:
audrasjb
Message:

Twenty Fifteen: Bundle Google Fonts locally.

This changeset bundles the Google Fonts used by Twenty Fifteen 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/twentyfifteen
Files:
90 added
2 edited

Legend:

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

    r54492 r55268  
    171171        /*
    172172         * This theme styles the visual editor to resemble the theme style,
    173          * specifically font, colors, icons, and column width.
    174          */
    175         add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) );
     173         * specifically font, colors, icons, and column width. When fonts are
     174         * self-hosted, the theme directory needs to be removed first.
     175         */
     176        $font_stylesheet = str_replace(
     177            array( get_template_directory_uri() . '/', get_stylesheet_directory_uri() . '/' ),
     178            '',
     179            twentyfifteen_fonts_url()
     180        );
     181        add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', $font_stylesheet ) );
    176182
    177183        // Load regular editor styles into the new block-based editor.
     
    348354if ( ! function_exists( 'twentyfifteen_fonts_url' ) ) :
    349355    /**
    350      * Register Google fonts for Twenty Fifteen.
     356     * Register fonts for Twenty Fifteen.
    351357     *
    352358     * @since Twenty Fifteen 1.0
     359
    353360     *
    354      * @return string Google fonts URL for the theme.
     361     * @return string onts URL for the theme.
    355362     */
    356363    function twentyfifteen_fonts_url() {
    357364        $fonts_url = '';
    358365        $fonts     = array();
    359         $subsets   = 'latin,latin-ext';
    360366
    361367        /*
     
    364370         */
    365371        if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'twentyfifteen' ) ) {
    366             $fonts[] = 'Noto Sans:400italic,700italic,400,700';
     372            $fonts[] = '';
    367373        }
    368374
     
    372378         */
    373379        if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'twentyfifteen' ) ) {
    374             $fonts[] = 'Noto Serif:400italic,700italic,400,700';
     380            $fonts[] = '';
    375381        }
    376382
     
    380386         */
    381387        if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentyfifteen' ) ) {
    382             $fonts[] = 'Inconsolata:400,700';
     388            $fonts[] = '';
    383389        }
    384390
    385         /*
    386          * translators: To add an additional character subset specific to your language,
    387          * translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language.
    388          */
    389         $subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen' );
    390 
    391         if ( 'cyrillic' === $subset ) {
    392             $subsets .= ',cyrillic,cyrillic-ext';
    393         } elseif ( 'greek' === $subset ) {
    394             $subsets .= ',greek,greek-ext';
    395         } elseif ( 'devanagari' === $subset ) {
    396             $subsets .= ',devanagari';
    397         } elseif ( 'vietnamese' === $subset ) {
    398             $subsets .= ',vietnamese';
    399         }
    400 
    401391        if ( $fonts ) {
    402             $fonts_url = add_query_arg(
    403                 array(
    404                     'family'  => urlencode( implode( '|', $fonts ) ),
    405                     'subset'  => urlencode( $subsets ),
    406                     'display' => urlencode( 'fallback' ),
    407                 ),
    408                 'https://fonts.googleapis.com/css'
    409             );
     392            $fonts_url = get_template_directory_uri() . '/assets/fonts/' . implode( '-plus-', $fonts ) . '.css';
    410393        }
    411394
     
    433416function twentyfifteen_scripts() {
    434417    // Add custom fonts, used in the main stylesheet.
    435     wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null );
     418    $font_version = ( 0 === strpos( (string) twentyfifteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     419    wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), $font_version );
    436420
    437421    // Add Genericons, used in the main stylesheet.
     
    483467    wp_enqueue_style( 'twentyfifteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20220908' );
    484468    // Add custom fonts.
    485     wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null );
     469    $font_version = ( 0 === strpos( (string) twentyfifteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     470    wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), $font_version );
    486471}
    487472add_action( 'enqueue_block_editor_assets', 'twentyfifteen_block_editor_styles' );
     
    492477 *
    493478 * @since Twenty Fifteen 1.7
     479
    494480 *
    495481 * @param array   $urls          URLs to print for resource hints.
     
    511497    return $urls;
    512498}
    513 add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 );
     499add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 );
    514500
    515501/**
  • trunk/src/wp-content/themes/twentyfifteen/readme.txt

    r55024 r55268  
    5353License: GNU GPL, Version 2 (or later)
    5454Source: http://www.genericons.com
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
    5570
    5671Block Pattern Images
Note: See TracChangeset for help on using the changeset viewer.