Changeset 49574 for trunk/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php
- Timestamp:
- 11/12/2020 06:34:44 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php
r49478 r49574 1 1 <?php 2 2 /** 3 * Custom ColorsClass3 * Dark Mode Class 4 4 * 5 5 * @package WordPress … … 9 9 10 10 /** 11 * This class is in charge of color customization via the Customizer.11 * This class is in charge of Dark Mode. 12 12 */ 13 13 class Twenty_Twenty_One_Dark_Mode { … … 41 41 42 42 // 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' ) ); 44 44 45 45 // Add the switch in the editor. 46 46 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' ) ); 47 50 } 48 51 … … 63 66 $should_respect_color_scheme = get_theme_mod( 'respect_user_color_preference', false ); 64 67 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. 66 69 wp_add_inline_style( 67 70 '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); }' 69 72 ); 70 73 } … … 99 102 return; 100 103 } 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. 107 109 } 108 110 … … 127 129 true 128 130 ); 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 );137 131 } 138 132 … … 149 143 */ 150 144 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 151 152 $wp_customize->add_setting( 152 153 'respect_user_color_preference', … … 165 166 'type' => 'checkbox', 166 167 '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' ), 169 170 'active_callback' => function( $value ) { 170 171 return 127 < Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) ); … … 329 330 z-index: 20; 330 331 } 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) { 332 333 color: var(--global--color-primary); 333 334 } … … 387 388 wp_die(); 388 389 } 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 389 410 }
Note: See TracChangeset
for help on using the changeset viewer.