Make WordPress Core


Ignore:
Timestamp:
10/20/2020 06:24:33 PM (4 years ago)
Author:
desrosj
Message:

Twenty Twenty: Import the latest changes from GitHub

For a full list of changes since [49216], see https://github.com/WordPress/twentytwentyone/compare/dfe141276ca4b856bbcd748f9da108ddad026c4c...trunk/.

Props poena, melchoyce, luminuu, aristath, jffng, ryelle, kishanjasani, rolfsiebers, sresok, desrosj.
See #51526.

File:
1 edited

Legend:

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

    r49216 r49247  
    4141        /*
    4242         * Let WordPress manage the document title.
    43          * By adding theme support, we declare that this theme does not use a
    44          * hard-coded <title> tag in the document head, and expect WordPress to
    45          * provide it for us.
     43         * This theme does not use a hard-coded <title> tag in the document head,
     44         * WordPress will provide it for us.
    4645         */
    4746        add_theme_support( 'title-tag' );
     
    127126        // Add support for editor styles.
    128127        add_theme_support( 'editor-styles' );
     128        $background_color = get_theme_mod( 'background_color', 'D1E4DD' );
     129        if ( 127 > Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( $background_color ) ) {
     130            add_theme_support( 'dark-editor-style' );
     131        }
    129132
    130133        $editor_stylesheet_path = './assets/css/style-editor.css';
     
    146149                array(
    147150                    'name'      => esc_html__( 'Extra small', 'twentytwentyone' ),
    148                     'shortName' => esc_html__( 'XS', 'twentytwentyone' ),
     151                    'shortName' => esc_html_x( 'XS', 'Font size', 'twentytwentyone' ),
    149152                    'size'      => 16,
    150153                    'slug'      => 'extra-small',
     
    152155                array(
    153156                    'name'      => esc_html__( 'Small', 'twentytwentyone' ),
    154                     'shortName' => esc_html__( 'S', 'twentytwentyone' ),
     157                    'shortName' => esc_html_x( 'S', 'Font size', 'twentytwentyone' ),
    155158                    'size'      => 18,
    156159                    'slug'      => 'small',
     
    158161                array(
    159162                    'name'      => esc_html__( 'Normal', 'twentytwentyone' ),
    160                     'shortName' => esc_html__( 'M', 'twentytwentyone' ),
     163                    'shortName' => esc_html_x( 'M', 'Font size', 'twentytwentyone' ),
    161164                    'size'      => 20,
    162165                    'slug'      => 'normal',
     
    164167                array(
    165168                    'name'      => esc_html__( 'Large', 'twentytwentyone' ),
    166                     'shortName' => esc_html__( 'L', 'twentytwentyone' ),
     169                    'shortName' => esc_html_x( 'L', 'Font size', 'twentytwentyone' ),
    167170                    'size'      => 24,
    168171                    'slug'      => 'large',
     
    170173                array(
    171174                    'name'      => esc_html__( 'Extra Large', 'twentytwentyone' ),
    172                     'shortName' => esc_html__( 'XL', 'twentytwentyone' ),
     175                    'shortName' => esc_html_x( 'XL', 'Font size', 'twentytwentyone' ),
    173176                    'size'      => 40,
    174177                    'slug'      => 'extra-large',
     
    176179                array(
    177180                    'name'      => esc_html__( 'Huge', 'twentytwentyone' ),
    178                     'shortName' => esc_html__( 'XXL', 'twentytwentyone' ),
     181                    'shortName' => esc_html_x( 'XXL', 'Font size', 'twentytwentyone' ),
    179182                    'size'      => 96,
    180183                    'slug'      => 'huge',
     
    182185                array(
    183186                    'name'      => esc_html__( 'Gigantic', 'twentytwentyone' ),
    184                     'shortName' => esc_html__( 'XXXL', 'twentytwentyone' ),
     187                    'shortName' => esc_html_x( 'XXXL', 'Font size', 'twentytwentyone' ),
    185188                    'size'      => 144,
    186189                    'slug'      => 'gigantic',
     
    523526function twentytwentyone_customize_preview_init() {
    524527    wp_enqueue_script(
     528        'twentytwentyone-customize-helpers',
     529        get_theme_file_uri( '/assets/js/customize-helpers.js' ),
     530        array(),
     531        wp_get_theme()->get( 'Version' ),
     532        true
     533    );
     534
     535    wp_enqueue_script(
    525536        'twentytwentyone-customize-preview',
    526537        get_theme_file_uri( '/assets/js/customize-preview.js' ),
    527         array( 'customize-preview', 'customize-selective-refresh', 'jquery' ),
    528         get_theme_file_path( 'assets/js/customize-preview.js' ),
     538        array( 'customize-preview', 'customize-selective-refresh', 'jquery', 'twentytwentyone-customize-helpers' ),
     539        wp_get_theme()->get( 'Version' ),
    529540        true
    530541    );
     
    532543add_action( 'customize_preview_init', 'twentytwentyone_customize_preview_init' );
    533544
    534 /**
    535  * Calculate any classes we may want to add to the main <html> element.
     545
     546/**
     547 * Enqueue scripts for the customizer.
     548 *
     549 * @since 1.0.0
     550 *
     551 * @return void
     552 */
     553function twentytwentyone_customize_controls_enqueue_scripts() {
     554
     555    wp_enqueue_script(
     556        'twentytwentyone-customize-helpers',
     557        get_theme_file_uri( '/assets/js/customize-helpers.js' ),
     558        array(),
     559        wp_get_theme()->get( 'Version' ),
     560        true
     561    );
     562
     563    wp_enqueue_script(
     564        'twentytwentyone-customize-controls',
     565        get_theme_file_uri( '/assets/js/customize.js' ),
     566        array( 'customize-base', 'customize-controls', 'underscore', 'jquery', 'twentytwentyone-customize-helpers' ),
     567        wp_get_theme()->get( 'Version' ),
     568        true
     569    );
     570
     571    wp_localize_script(
     572        'twentytwentyone-customize-controls',
     573        'backgroundColorNotice',
     574        array(
     575            'message' => esc_html__( 'You currently have dark mode enabled on your device. Changing the color picker will allow you to preview light mode.', 'twentytwentyone' ),
     576        )
     577    );
     578}
     579add_action( 'customize_controls_enqueue_scripts', 'twentytwentyone_customize_controls_enqueue_scripts' );
     580
     581/**
     582 * Calculate classes for the main <html> element.
    536583 *
    537584 * @since 1.0.0
     
    540587 */
    541588function twentytwentyone_the_html_classes() {
    542     $background_color             = get_theme_mod( 'background_color', 'D1E4DD' );
    543     $light_colors_default_palette = array( '#D1E4DD', '#D1DFE4', '#D1D1E4', '#E4D1D1', '#E4DAD1', '#EEEADD', '#FFFFFF' );
    544     if ( in_array( strtoupper( '#' . ltrim( $background_color, '#' ) ), $light_colors_default_palette, true ) ) {
    545         echo 'class="has-default-light-palette-background"';
    546     }
    547 }
     589    $background_color            = get_theme_mod( 'background_color', 'D1E4DD' );
     590    $should_respect_color_scheme = get_theme_mod( 'respect_user_color_preference', true );
     591    if ( $should_respect_color_scheme && 127 <= Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( $background_color ) ) {
     592        echo 'class="respect-color-scheme-preference"';
     593    }
     594}
Note: See TracChangeset for help on using the changeset viewer.