Make WordPress Core


Ignore:
Timestamp:
10/20/2020 06:24:33 PM (6 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/classes/class-twenty-twenty-one-custom-colors.php

    r49216 r49247  
    3333
    3434        /**
    35          * Determine the luminance of the given color and then return #fff or #000 so that our text is always readable.
     35         * Determine the luminance of the given color and then return #fff or #000 so that the text is always readable.
    3636         *
    3737         * @access public
     
    4444         */
    4545        public function custom_get_readable_color( $background_color ) {
    46                 return ( 127 < $this->get_relative_luminance_from_hex( $background_color ) ) ? '#000' : '#fff';
     46                return ( 127 < self::get_relative_luminance_from_hex( $background_color ) ) ? '#000' : '#fff';
    4747        }
    4848
     
    116116                        (string) filemtime( get_theme_file_path( 'assets/css/custom-color-overrides.css' ) )
    117117                );
    118                 if ( 'd1e4dd' !== strtolower( get_theme_mod( 'background_color', 'D1E4DD' ) ) ) {
     118
     119                $background_color = get_theme_mod( 'background_color', 'D1E4DD' );
     120                if ( 'd1e4dd' !== strtolower( $background_color ) ) {
    119121                        wp_add_inline_style( 'twenty-twenty-one-custom-color-overrides', $this->generate_custom_color_variables( 'editor' ) );
     122                }
     123
     124                $should_respect_color_scheme = get_theme_mod( 'respect_user_color_preference', true ); // @phpstan-ignore-line. Passing true instead of default value of false to get_theme_mod.
     125                if ( $should_respect_color_scheme && self::get_relative_luminance_from_hex( $background_color ) > 127 ) {
     126                        // Add dark mode variable overrides.
     127                        wp_add_inline_style( 'twenty-twenty-one-custom-color-overrides', '@media (prefers-color-scheme: dark) { :root .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); } }' );
    120128                }
    121129        }
     
    123131        /**
    124132         * Get luminance from a HEX color.
     133         *
     134         * @static
    125135         *
    126136         * @access public
     
    132142         * @return int Returns a number (0-255).
    133143         */
    134         public function get_relative_luminance_from_hex( $hex ) {
     144        public static function get_relative_luminance_from_hex( $hex ) {
    135145
    136146                // Remove the "#" symbol from the beginning of the color.
    137147                $hex = ltrim( $hex, '#' );
    138148
    139                 // Make sure we have 6 digits for the below calculations.
     149                // Make sure there are 6 digits for the below calculations.
    140150                if ( 3 === strlen( $hex ) ) {
    141151                        $hex = substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 2, 1 ) . substr( $hex, 2, 1 );
     
    165175        public function body_class( $classes ) {
    166176                $background_color = get_theme_mod( 'background_color', 'D1E4DD' );
    167                 if ( 127 > $this->get_relative_luminance_from_hex( $background_color ) ) {
     177                if ( 127 > self::get_relative_luminance_from_hex( $background_color ) ) {
    168178                        $classes[] = 'is-background-dark';
    169179                } else {
     
    171181                }
    172182
    173                 $light_colors_default_palette = array( '#D1E4DD', '#D1DFE4', '#D1D1E4', '#E4D1D1', '#E4DAD1', '#EEEADD', '#FFFFFF' );
    174                 if ( in_array( strtoupper( '#' . ltrim( $background_color, '#' ) ), $light_colors_default_palette, true ) ) {
    175                         $classes[] = 'has-default-light-palette-background';
    176                 }
    177 
    178183                return $classes;
    179184        }
Note: See TracChangeset for help on using the changeset viewer.