WordPress.org

Make WordPress Core

Ticket #45928: 45928.5.diff

File 45928.5.diff, 10.1 KB (added by davidbaumwald, 3 months ago)

Refreshed Patch

  • src/wp-content/themes/twentynineteen/functions.php

    diff --git a/src/wp-content/themes/twentynineteen/functions.php b/src/wp-content/themes/twentynineteen/functions.php
    index 901aa29990..8c941807c4 100644
    a b if ( ! function_exists( 'twentynineteen_setup' ) ) : 
    138138                        )
    139139                );
    140140
     141                $default_hue     = twentynineteen_get_default_hue();
     142                $saturation      = apply_filters( 'twentynineteen_custom_colors_saturation', 100 );
     143                $lightness       = apply_filters( 'twentynineteen_custom_colors_lightness', 33 );
     144                $lightness_hover = apply_filters( 'twentynineteen_custom_colors_lightness_hover', 23 );
     145
    141146                // Editor color palette.
    142147                add_theme_support(
    143148                        'editor-color-palette',
    if ( ! function_exists( 'twentynineteen_setup' ) ) : 
    145150                                array(
    146151                                        'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Blue', 'twentynineteen' ) : null,
    147152                                        'slug'  => 'primary',
    148                                         'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
     153                                        'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? $default_hue : get_theme_mod( 'primary_color_hue', $default_hue ), $saturation, $lightness ),
    149154                                ),
    150155                                array(
    151156                                        'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Dark Blue', 'twentynineteen' ) : null,
    152157                                        'slug'  => 'secondary',
    153                                         'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
     158                                        'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? $default_hue : get_theme_mod( 'primary_color_hue', $default_hue ), $saturation, 23 ),
    154159                                ),
    155160                                array(
    156161                                        'name'  => __( 'Dark Gray', 'twentynineteen' ),
    function twentynineteen_colors_css_wrap() { 
    279284
    280285        require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
    281286
    282         $primary_color = 199;
     287        $primary_color = twentynineteen_get_default_hue();
    283288        if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
    284                 $primary_color = get_theme_mod( 'primary_color_hue', 199 );
     289                $primary_color = get_theme_mod( 'primary_color_hue', $primary_color );
    285290        }
    286291        ?>
    287292
    function twentynineteen_colors_css_wrap() { 
    292297}
    293298add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
    294299
     300/**
     301 *  Default color filters.
     302 */
     303require get_template_directory() . '/inc/color-filters.php';
     304
    295305/**
    296306 * SVG Icons class.
    297307 */
  • new file src/wp-content/themes/twentynineteen/inc/color-filters.php

    diff --git a/src/wp-content/themes/twentynineteen/inc/color-filters.php b/src/wp-content/themes/twentynineteen/inc/color-filters.php
    new file mode 100644
    index 0000000000..e83479c870
    - +  
     1<?php
     2/**
     3 * Twenty Nineteen: Color Filter for overriding the colors schemes in a child theme
     4 *
     5 * @package WordPress
     6 * @subpackage TwentyNineteen
     7 * @since 1.0
     8 */
     9
     10/**
     11 * Define default color filters.
     12 */
     13
     14define( 'TWENTYNINETEEN_DEFAULT_HUE', 199 );        // H
     15define( 'TWENTYNINETEEN_DEFAULT_SATURATION', 100 ); // S
     16define( 'TWENTYNINETEEN_DEFAULT_LIGHTNESS', 33 );   // L
     17
     18define( 'TWENTYNINETEEN_DEFAULT_SATURATION_SELECTION', 50 );
     19define( 'TWENTYNINETEEN_DEFAULT_LIGHTNESS_SELECTION', 90 );
     20define( 'TWENTYNINETEEN_DEFAULT_LIGHTNESS_HOVER', 23 );
     21
     22/**
     23 * The default hue (as in hsl) used for the primary color throughout this theme
     24 *
     25 * @return number the default hue
     26 */
     27function twentynineteen_get_default_hue() {
     28        return apply_filters( 'twentynineteen_default_hue', TWENTYNINETEEN_DEFAULT_HUE );
     29}
     30
     31/**
     32 * The default saturation (as in hsl) used for the primary color throughout this theme
     33 *
     34 * @return number the default saturation
     35 */
     36function twentynineteen_get_default_saturation() {
     37        return apply_filters( 'twentynineteen_default_saturation', TWENTYNINETEEN_DEFAULT_SATURATION );
     38}
     39
     40/**
     41 * The default lightness (as in hsl) used for the primary color throughout this theme
     42 *
     43 * @return number the default lightness
     44 */
     45function twentynineteen_get_default_lightness() {
     46        return apply_filters( 'twentynineteen_default_lightness', TWENTYNINETEEN_DEFAULT_LIGHTNESS );
     47}
     48
     49/**
     50 * The default saturation (as in hsl) used when selecting text throughout this theme
     51 *
     52 * @return number the default saturation selection
     53 */
     54function twentynineteen_get_default_saturation_selection() {
     55        return apply_filters( 'twentynineteen_default_saturation_selection', TWENTYNINETEEN_DEFAULT_SATURATION_SELECTION );
     56}
     57
     58/**
     59 * The default lightness (as in hsl) used when selecting text throughout this theme
     60 *
     61 * @return number the default lightness selection
     62 */
     63function twentynineteen_get_default_lightness_selection() {
     64        return apply_filters( 'twentynineteen_default_lightness_selection', TWENTYNINETEEN_DEFAULT_LIGHTNESS_SELECTION );
     65}
     66
     67/**
     68 * The default lightness hover (as in hsl) used when hovering over links throughout this theme
     69 *
     70 * @return number the default lightness hover
     71 */
     72function twentynineteen_get_default_lightness_hover() {
     73        return apply_filters( 'twentynineteen_default_lightness_hover', TWENTYNINETEEN_DEFAULT_LIGHTNESS_HOVER );
     74}
     75
     76function twentynineteen_has_custom_default_hue() {
     77        return twentynineteen_get_default_hue() !== TWENTYNINETEEN_DEFAULT_HUE;
     78}
  • src/wp-content/themes/twentynineteen/inc/color-patterns.php

    diff --git a/src/wp-content/themes/twentynineteen/inc/color-patterns.php b/src/wp-content/themes/twentynineteen/inc/color-patterns.php
    index c16c1d6a49..4813c09d50 100644
    a b  
    1212 */
    1313function twentynineteen_custom_colors_css() {
    1414
    15         $primary_color = 199;
     15        $primary_color = twentynineteen_get_default_hue();
    1616        if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
    17                 $primary_color = absint( get_theme_mod( 'primary_color_hue', 199 ) );
     17                $primary_color = absint( get_theme_mod( 'primary_color_hue', $primary_color ) );
    1818        }
    1919
    2020        /**
    function twentynineteen_custom_colors_css() { 
    2424         *
    2525         * @param int $saturation Color saturation level.
    2626         */
    27         $saturation = apply_filters( 'twentynineteen_custom_colors_saturation', 100 );
     27        $saturation = twentynineteen_get_default_saturation();
    2828        $saturation = absint( $saturation ) . '%';
    2929
    3030        /**
    function twentynineteen_custom_colors_css() { 
    3434         *
    3535         * @param int $saturation_selection Selection color saturation level.
    3636         */
    37         $saturation_selection = absint( apply_filters( 'twentynineteen_custom_colors_saturation_selection', 50 ) );
    38         $saturation_selection = $saturation_selection . '%';
     37        $saturation_selection = twentynineteen_get_default_saturation_selection();
     38        $saturation_selection = absint( $saturation_selection ) . '%';
    3939
    4040        /**
    4141         * Filter Twenty Nineteen default lightness level.
    function twentynineteen_custom_colors_css() { 
    4444         *
    4545         * @param int $lightness Color lightness level.
    4646         */
    47         $lightness = apply_filters( 'twentynineteen_custom_colors_lightness', 33 );
     47        $lightness = twentynineteen_get_default_lightness();
    4848        $lightness = absint( $lightness ) . '%';
    4949
    5050        /**
    function twentynineteen_custom_colors_css() { 
    5454         *
    5555         * @param int $lightness_hover Hover color lightness level.
    5656         */
    57         $lightness_hover = apply_filters( 'twentynineteen_custom_colors_lightness_hover', 23 );
     57        $lightness_hover = twentynineteen_get_default_lightness_hover();
    5858        $lightness_hover = absint( $lightness_hover ) . '%';
    5959
    6060        /**
    function twentynineteen_custom_colors_css() { 
    6464         *
    6565         * @param int $lightness_selection Selection color lightness level.
    6666         */
    67         $lightness_selection = apply_filters( 'twentynineteen_custom_colors_lightness_selection', 90 );
     67        $lightness_selection = twentynineteen_get_default_lightness_selection();
    6868        $lightness_selection = absint( $lightness_selection ) . '%';
    6969
    7070        $theme_css = '
  • src/wp-content/themes/twentynineteen/inc/customizer.php

    diff --git a/src/wp-content/themes/twentynineteen/inc/customizer.php b/src/wp-content/themes/twentynineteen/inc/customizer.php
    index b0a784e930..c979e441c9 100644
    a b function twentynineteen_customize_register( $wp_customize ) { 
    6464        $wp_customize->add_setting(
    6565                'primary_color_hue',
    6666                array(
    67                         'default'           => 199,
     67                        'default'           => twentynineteen_get_default_hue(),
    6868                        'transport'         => 'postMessage',
    6969                        'sanitize_callback' => 'absint',
    7070                )
    function twentynineteen_customize_partial_blogdescription() { 
    125125 * Bind JS handlers to instantly live-preview changes.
    126126 */
    127127function twentynineteen_customize_preview_js() {
    128         wp_enqueue_script( 'twentynineteen-customize-preview', get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-preview' ), '20181214', true );
     128        wp_enqueue_script( 'twentynineteen-customize-preview', get_theme_file_uri( '/js/customize-preview.js' ), array( 'customize-preview' ), '20181214', true );wp_localize_script(
     129                'twentynineteen-customize-preview',
     130                '_TwentyNineteenPreviewData',
     131                array(
     132                        'default_hue' => twentynineteen_get_default_hue(),
     133                )
     134        );
    129135}
    130136add_action( 'customize_preview_init', 'twentynineteen_customize_preview_js' );
    131137
  • src/wp-content/themes/twentynineteen/js/customize-preview.js

    diff --git a/src/wp-content/themes/twentynineteen/js/customize-preview.js b/src/wp-content/themes/twentynineteen/js/customize-preview.js
    index 91b91f3e0c..429105d0a6 100644
    a b  
     1/* global _TwentyNineteenPreviewData */
    12/**
    23 * File customize-preview.js.
    34 *
     
    1718                                css = style.html(),
    1819                                color;
    1920
    20                         if( 'custom' === to ){
     21                        if ( 'custom' === to ) {
    2122                                // If a custom primary color is selected, use the currently set primary_color_hue
    2223                                color = wp.customize.get().primary_color_hue;
    2324                        } else {
    2425                                // If the "default" option is selected, get the default primary_color_hue
    25                                 color = 199;
     26                                color = _TwentyNineteenPreviewData.default_hue;
    2627                        }
    2728
    2829                        // Equivalent to css.replaceAll, with hue followed by comma to prevent values with units from being changed.