Make WordPress Core


Ignore:
Timestamp:
02/07/2023 03:57:06 PM (21 months ago)
Author:
audrasjb
Message:

Twenty Fourteen: Bundle Google Fonts locally.

This changeset bundles the Google Fonts used by Twenty Fourteen 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.

File:
1 edited

Legend:

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

    r54492 r55270  
    6868        load_theme_textdomain( 'twentyfourteen' );
    6969
    70         // This theme styles the visual editor to resemble the theme style.
    71         add_editor_style( array( 'css/editor-style.css', twentyfourteen_font_url(), 'genericons/genericons.css' ) );
     70        /*
     71         * This theme styles the visual editor to resemble the theme style.
     72         * When fonts are self-hosted, the theme directory needs to be removed first.
     73         */
     74        $font_stylesheet = str_replace(
     75            array( get_template_directory_uri() . '/', get_stylesheet_directory_uri() . '/' ),
     76            '',
     77            twentyfourteen_font_url()
     78        );
     79        add_editor_style( array( 'css/editor-style.css', $font_stylesheet, 'genericons/genericons.css' ) );
    7280
    7381        // Load regular editor styles into the new block-based editor.
     
    294302add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
    295303
    296 /**
    297  * Register Lato Google font for Twenty Fourteen.
    298  *
    299  * @since Twenty Fourteen 1.0
    300  *
    301  * @return string
    302  */
    303 function twentyfourteen_font_url() {
    304     $font_url = '';
    305     /*
    306      * translators: If there are characters in your language that are not supported
    307      * by Lato, translate this to 'off'. Do not translate into your own language.
     304if ( ! function_exists( 'twentyfourteen_font_url' ) ) :
     305    /**
     306     * Register Lato font for Twenty Fourteen.
     307     *
     308     * @since Twenty Fourteen 1.0
     309     * @since Twenty Fourteen 3.6 Replaced Google URL with self-hosted fonts.
     310     *
     311     * @return string
    308312     */
    309     if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
    310         $query_args = array(
    311             'family'  => urlencode( 'Lato:300,400,700,900,300italic,400italic,700italic' ),
    312             'subset'  => urlencode( 'latin,latin-ext' ),
    313             'display' => urlencode( 'fallback' ),
    314         );
    315         $font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    316     }
    317 
    318     return $font_url;
    319 }
     313    function twentyfourteen_font_url() {
     314        $font_url = '';
     315        /*
     316         * translators: If there are characters in your language that are not supported
     317         * by Lato, translate this to 'off'. Do not translate into your own language.
     318         */
     319        if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
     320            $font_url = get_template_directory_uri() . '/fonts/font-lato.css';
     321        }
     322
     323        return $font_url;
     324    }
     325endif;
    320326
    321327/**
     
    326332function twentyfourteen_scripts() {
    327333    // Add Lato font, used in the main stylesheet.
    328     wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), null );
     334    $font_version = ( 0 === strpos( (string) twentyfourteen_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     335    wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), $font_version );
    329336
    330337    // Add Genericons font, used in the main stylesheet.
     
    370377
    371378/**
    372  * Enqueue Google fonts style to admin screen for custom header display.
     379 * Enqueue font stylesheet to admin screen for custom header display.
    373380 *
    374381 * @since Twenty Fourteen 1.0
    375382 */
    376383function twentyfourteen_admin_fonts() {
    377     wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), null );
     384    $font_version = ( 0 === strpos( (string) twentyfourteen_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     385    wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), $font_version );
    378386}
    379387add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' );
     
    383391 *
    384392 * @since Twenty Fourteen 1.9
     393 * @deprecated Twenty Fourteen 3.6 Disabled filter because, by default, fonts are self-hosted.
    385394 *
    386395 * @param array   $urls          URLs to print for resource hints.
     
    402411    return $urls;
    403412}
    404 add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 );
     413// add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 );
    405414
    406415/**
     
    413422    wp_enqueue_style( 'twentyfourteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20210216' );
    414423    // Add custom fonts.
    415     wp_enqueue_style( 'twentyfourteen-fonts', twentyfourteen_font_url(), array(), null );
     424    $font_version = ( 0 === strpos( (string) twentyfourteen_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
     425    wp_enqueue_style( 'twentyfourteen-fonts', twentyfourteen_font_url(), array(), $font_version );
    416426}
    417427add_action( 'enqueue_block_editor_assets', 'twentyfourteen_block_editor_styles' );
Note: See TracChangeset for help on using the changeset viewer.