WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/26/2012 06:44:31 PM (8 years ago)
Author:
koopersmith
Message:

Theme Customizer: Ensure that JS color controls always use real color values, even if the server-side value is a hex value without a hash. fixes #20448, see #19910.

Adds WP_Customize_Setting->sanitize_js_callback and 'customize_sanitize_js_$settingID' filter, to filter values before they're passed to JS using WP_Customize_Setting->js_value().

Adds support for regular hex colors to the color picker.

Changes color methods:

  • sanitize_hex_color() accepts 3 and 6 digit hex colors (with hashes) and the empty string.
  • sanitize_hex_color_no_hash() accepts 3 and 6 digit hex colors (without hashes) and the empty string.
  • maybe_hash_hex_color() ensures that a hex color has a hash, and otherwise leaves the value untouched.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-customize-setting.php

    r20809 r20936  
    1212    public $id;
    1313
    14     public $type              = 'theme_mod';
    15     public $capability        = 'edit_theme_options';
    16     public $theme_supports    = '';
    17     public $default           = '';
    18     public $sanitize_callback = '';
    19     public $transport         = 'refresh';
     14    public $type            = 'theme_mod';
     15    public $capability      = 'edit_theme_options';
     16    public $theme_supports  = '';
     17    public $default         = '';
     18    public $transport       = 'refresh';
     19
     20    public $sanitize_callback    = '';
     21    public $sanitize_js_callback = '';
    2022
    2123    protected $id_data = array();
     
    5052            $this->id .= '[' . implode( '][', $this->id_data[ 'keys' ] ) . ']';
    5153
    52         if ( $this->sanitize_callback != '' )
    53             add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback );
     54        if ( $this->sanitize_callback )
     55            add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 );
     56
     57        if ( $this->sanitize_js_callback )
     58            add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 );
    5459
    5560        return $this;
     
    139144    public function sanitize( $value ) {
    140145        $value = stripslashes_deep( $value );
    141         return apply_filters( "customize_sanitize_{$this->id}", $value );
     146        return apply_filters( "customize_sanitize_{$this->id}", $value, $this );
    142147    }
    143148
     
    239244     */
    240245    public function js_value() {
    241         $value = $this->value();
     246        $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this );
    242247
    243248        if ( is_string( $value ) )
Note: See TracChangeset for help on using the changeset viewer.