Make WordPress Core


Ignore:
Timestamp:
11/12/2020 06:34:44 PM (5 years ago)
Author:
desrosj
Message:

Twenty Twenty-One: Merge the latest changes changes from GitHub for Beta 4.

In addition to syncing the latest changes, this change also merges the theme’s .scss files and other related build tool configurations required to compile the theme’s CSS.

This will allow development of the theme to continue on Trac after 5.6 is released and the GitHub repository is archived.

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

Props poena, luminuu kjellr, aristath, justinahinon.
See #51526.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php

    r49478 r49574  
    11<?php
    22/**
    3  * Custom Colors Class
     3 * Dark Mode Class
    44 *
    55 * @package WordPress
     
    99
    1010/**
    11  * This class is in charge of color customization via the Customizer.
     11 * This class is in charge of Dark Mode.
    1212 */
    1313class Twenty_Twenty_One_Dark_Mode {
     
    4141
    4242        // Add the switch on the frontend & customizer.
    43         add_action( 'get_template_part_template-parts/header/site-nav', array( $this, 'the_switch' ) );
     43        add_action( 'wp_footer', array( $this, 'the_switch' ) );
    4444
    4545        // Add the switch in the editor.
    4646        add_action( 'wp_ajax_tt1_dark_mode_editor_switch', array( $this, 'editor_ajax_callback' ) );
     47
     48        // Add the privacy policy content.
     49        add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) );
    4750    }
    4851
     
    6366        $should_respect_color_scheme = get_theme_mod( 'respect_user_color_preference', false );
    6467        if ( $should_respect_color_scheme && Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( $background_color ) > 127 ) {
    65             // Add dark mode variable overrides.
     68            // Add Dark Mode variable overrides.
    6669            wp_add_inline_style(
    6770                'twenty-twenty-one-custom-color-overrides',
    68                 'html.is-dark-mode .editor-styles-wrapper { --global--color-background: var(--global--color-dark-gray); --global--color-primary: var(--global--color-light-gray); --global--color-secondary: var(--global--color-light-gray); }'
     71                '.is-dark-theme.is-dark-theme .editor-styles-wrapper { --global--color-background: var(--global--color-dark-gray); --global--color-primary: var(--global--color-light-gray); --global--color-secondary: var(--global--color-light-gray); }'
    6972            );
    7073        }
     
    99102            return;
    100103        }
    101         wp_enqueue_style(
    102             'tt1-dark-mode',
    103             get_template_directory_uri() . '/assets/css/style-dark-mode.css',
    104             array( 'twenty-twenty-one-style' ),
    105             '1.0.0'
    106         );
     104        $url = get_template_directory_uri() . '/assets/css/style-dark-mode.css';
     105        if ( is_rtl() ) {
     106            $url = get_template_directory_uri() . '/assets/css/style-dark-mode-rtl.css';
     107        }
     108        wp_enqueue_style( 'tt1-dark-mode', $url, array( 'twenty-twenty-one-style' ), wp_get_theme()->get( 'Version' ) ); // @phpstan-ignore-line. Version is always a string.
    107109    }
    108110
     
    127129            true
    128130        );
    129 
    130         wp_localize_script(
    131             'twentytwentyone-customize-controls',
    132             'backgroundColorNotice',
    133             array(
    134                 'message' => esc_html__( 'Changes will only be visible if Dark Mode is "Off" in the preview', 'twentytwentyone' ),
    135             )
    136         );
    137131    }
    138132
     
    149143     */
    150144    public function customizer_controls( $wp_customize ) {
     145
     146        $colors_section = $wp_customize->get_section( 'colors' );
     147        if ( is_object( $colors_section ) ) {
     148            $colors_section->title       = __( 'Colors & Dark Mode', 'twentytwentyone' );
     149            $colors_section->description = __( 'To access the Dark Mode settings, select a light background color.', 'twentytwentyone' ) . '<br><a href="https://wordpress.org/support/article/twenty-twenty-one/">' . __( 'Learn more about Dark Mode.', 'twentytwentyone' ) . '</a>';
     150        }
     151
    151152        $wp_customize->add_setting(
    152153            'respect_user_color_preference',
     
    165166                'type'            => 'checkbox',
    166167                'section'         => 'colors',
    167                 'label'           => esc_html__( 'Respect visitor\'s device dark mode settings', 'twentytwentyone' ),
    168                 'description'     => __( 'Dark mode is a device setting. If a visitor to your site requests it, your site will be shown with a dark background and light text.', 'twentytwentyone' ),
     168                'label'           => esc_html__( 'Dark Mode Support', 'twentytwentyone' ),
     169                'description'     => __( 'Respect visitor\'s device dark mode settings.<br>Dark mode is a device setting. If a visitor to your site requests it, your site will be shown with a dark background and light text.<br><br>Dark Mode can also be turned on and off with a button that you can find in the bottom right corner of the page.', 'twentytwentyone' ),
    169170                'active_callback' => function( $value ) {
    170171                    return 127 < Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
     
    329330                    z-index: 20;
    330331                }
    331                 html.is-dark-mode #dark-mode-toggler:not(:hover):not(:focus) {
     332                .is-dark-theme.is-dark-theme #dark-mode-toggler:not(:hover):not(:focus) {
    332333                    color: var(--global--color-primary);
    333334                }
     
    387388        wp_die();
    388389    }
     390
     391    /**
     392     * Adds information to the privacy policy.
     393     *
     394     * @access public
     395     *
     396     * @since 1.0.0
     397     *
     398     * @return void
     399     */
     400    public function add_privacy_policy_content() {
     401        if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
     402            return;
     403        }
     404        $content = '<p class="privacy-policy-tutorial">' . __( 'Twenty Twenty-One uses LocalStorage when Dark Mode support is enabled.', 'twentytwentyone' ) . '</p>'
     405                . '<strong class="privacy-policy-tutorial">' . __( 'Suggested Text:', 'twentytwentyone' ) . '</strong> '
     406                . __( 'This website uses LocalStorage to save the setting when Dark Mode support is turned on or off.<br> LocalStorage is necessary for the setting to work and is only used when a user clicks on the Dark Mode button.<br> No data is saved in the database or transferred.', 'twentytwentyone' );
     407        wp_add_privacy_policy_content( 'Twenty Twenty-One', wp_kses_post( wpautop( $content, false ) ) );
     408    }
     409
    389410}
Note: See TracChangeset for help on using the changeset viewer.