Make WordPress Core


Ignore:
Timestamp:
11/17/2020 06:58:52 PM (6 years ago)
Author:
desrosj
Message:

Twenty Twenty-One: Sync the latest changes for 5.6 RC1.

For a full list of changes since [49574-49577], see ​https://github.com/WordPress/twentytwentyone/compare/aa284fd...trunk.

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

File:
1 edited

Legend:

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

    r49578 r49633  
    4343                add_action( 'wp_footer', array( $this, 'the_switch' ) );
    4444
    45                 // Add the switch in the editor.
    46                 add_action( 'wp_ajax_tt1_dark_mode_editor_switch', array( $this, 'editor_ajax_callback' ) );
    47 
    4845                // Add the privacy policy content.
    4946                add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) );
    … …  
    146143                $colors_section = $wp_customize->get_section( 'colors' );
    147144                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                 }
     145                        $colors_section->title = __( 'Colors & Dark Mode', 'twentytwentyone' );
     146                }
     147
     148                // Custom notice control.
     149                include_once get_theme_file_path( 'classes/class-twenty-twenty-one-customize-notice-control.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
     150
     151                $wp_customize->add_setting(
     152                        'respect_user_color_preference_notice',
     153                        array(
     154                                'capability'        => 'edit_theme_options',
     155                                'default'           => '',
     156                                'sanitize_callback' => '__return_empty_string',
     157                        )
     158                );
     159
     160                $wp_customize->add_control(
     161                        new Twenty_Twenty_One_Customize_Notice_Control(
     162                                $wp_customize,
     163                                'respect_user_color_preference_notice',
     164                                array(
     165                                        'section'         => 'colors',
     166                                        'priority'        => 100,
     167                                        'active_callback' => function() {
     168                                                return 127 >= Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
     169                                        },
     170                                )
     171                        )
     172                );
    151173
    152174                $wp_customize->add_setting(
    … …  
    161183                );
    162184
     185                $description  = '<p>' . __( '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. <a href="https://wordpress.org/support/article/twenty-twenty-one/">Learn more about Dark Mode.</a>', 'twentytwentyone' ) . '</p>';
     186                $description .= '<p>' . __( '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' ) . '</p>';
     187
    163188                $wp_customize->add_control(
    164189                        'respect_user_color_preference',
    … …  
    167192                                'section'         => 'colors',
    168193                                'label'           => esc_html__( 'Dark Mode support', 'twentytwentyone' ),
    169                                 'description'     => __( 'Respect visitor&#8217;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' ),
     194                                'priority'        => 110,
     195                                'description'     => $description,
    170196                                'active_callback' => function( $value ) {
    171197                                        return 127 < Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
    … …  
    360386
    361387        /**
    362          * Print the dark-mode switch styles.
    363          *
    364          * @access public
    365          *
    366          * @since 1.0.0
    367          *
    368          * @return void
    369          */
    370         public function the_styles() {
    371                 echo '<style>';
    372                 include get_theme_file_path( 'assets/css/style-dark-mode.css' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
    373                 echo '</style>';
    374         }
    375 
    376         /**
    377          * Call the tt1_the_dark_mode_switch and exit.
    378          *
    379          * @access public
    380          *
    381          * @since 1.0.0
    382          *
    383          * @return void
    384          */
    385         public function editor_ajax_callback() {
    386                 $this->the_html();
    387                 $this->the_styles();
    388                 wp_die();
    389         }
    390 
    391         /**
    392388         * Adds information to the privacy policy.
    393389         *
Note: See TracChangeset for help on using the changeset viewer.