wppaste
WordPress

Twenty_Twenty_One_Dark_Mode

Source
wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php:13
This class is in charge of Dark Mode.

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Methods · 12

Source code

class Twenty_Twenty_One_Dark_Mode { 	/**	 * Instantiates the object.	 *	 * @since Twenty Twenty-One 1.0	 */	public function __construct() { 		// Enqueue assets for the block-editor.		if ( is_admin() ) {			add_action( 'enqueue_block_assets', array( $this, 'editor_custom_color_variables' ) );		} 		// Add styles for dark-mode.		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 		// Add scripts for customizer controls.		add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts' ) ); 		// Add customizer controls.		add_action( 'customize_register', array( $this, 'customizer_controls' ) ); 		// Add HTML classes.		add_filter( 'twentytwentyone_html_classes', array( $this, 'html_classes' ) ); 		// Add classes to <body> in the dashboard.		add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ) ); 		// Add the switch on the frontend & customizer.		add_action( 'wp_footer', array( $this, 'the_switch' ) ); 		// Add the privacy policy content.		add_action( 'admin_init', array( $this, 'add_privacy_policy_content' ) );	} 	/**	 * Enqueues editor custom color variables & scripts.	 *	 * @since Twenty Twenty-One 1.0	 *	 * @return void	 */	public function editor_custom_color_variables() {		if ( ! $this->switch_should_render() ) {			return;		}		$background_color            = get_theme_mod( 'background_color', 'D1E4DD' );		$should_respect_color_scheme = get_theme_mod( 'respect_user_color_preference', false );		if ( $should_respect_color_scheme && Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( $background_color ) > 127 ) {			// Add Dark Mode variable overrides.			wp_add_inline_style(				'twenty-twenty-one-custom-color-overrides',				'.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); --button--color-text: var(--global--color-background); --button--color-text-hover: var(--global--color-secondary); --button--color-text-active: var(--global--color-secondary); --button--color-background: var(--global--color-secondary); --button--color-background-active: var(--global--color-background); --global--color-border: #9ea1a7; --table--stripes-border-color: rgba(240, 240, 240, 0.15); --table--stripes-background-color: rgba(240, 240, 240, 0.15); }'			);		}		wp_enqueue_script(			'twentytwentyone-dark-mode-support-toggle',			get_template_directory_uri() . '/assets/js/dark-mode-toggler.js',			array(),			wp_get_theme()->get( 'Version' ),			array( 'in_footer' => true )		); 		wp_enqueue_script(			'twentytwentyone-editor-dark-mode-support',			get_template_directory_uri() . '/assets/js/editor-dark-mode-support.js',			array( 'twentytwentyone-dark-mode-support-toggle' ),			wp_get_theme()->get( 'Version' ),			array( 'in_footer' => true )		);	} 	/**	 * Enqueues scripts and styles.	 *	 * @since Twenty Twenty-One 1.0	 *	 * @return void	 */

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.