mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@20936 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -11,12 +11,14 @@ class WP_Customize_Setting {
|
||||
public $manager;
|
||||
public $id;
|
||||
|
||||
public $type = 'theme_mod';
|
||||
public $capability = 'edit_theme_options';
|
||||
public $theme_supports = '';
|
||||
public $default = '';
|
||||
public $sanitize_callback = '';
|
||||
public $transport = 'refresh';
|
||||
public $type = 'theme_mod';
|
||||
public $capability = 'edit_theme_options';
|
||||
public $theme_supports = '';
|
||||
public $default = '';
|
||||
public $transport = 'refresh';
|
||||
|
||||
public $sanitize_callback = '';
|
||||
public $sanitize_js_callback = '';
|
||||
|
||||
protected $id_data = array();
|
||||
private $_post_value; // Cached, sanitized $_POST value.
|
||||
@@ -49,8 +51,11 @@ class WP_Customize_Setting {
|
||||
if ( ! empty( $this->id_data[ 'keys' ] ) )
|
||||
$this->id .= '[' . implode( '][', $this->id_data[ 'keys' ] ) . ']';
|
||||
|
||||
if ( $this->sanitize_callback != '' )
|
||||
add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback );
|
||||
if ( $this->sanitize_callback )
|
||||
add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 );
|
||||
|
||||
if ( $this->sanitize_js_callback )
|
||||
add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 );
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -138,7 +143,7 @@ class WP_Customize_Setting {
|
||||
*/
|
||||
public function sanitize( $value ) {
|
||||
$value = stripslashes_deep( $value );
|
||||
return apply_filters( "customize_sanitize_{$this->id}", $value );
|
||||
return apply_filters( "customize_sanitize_{$this->id}", $value, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +243,7 @@ class WP_Customize_Setting {
|
||||
* @return mixed The requested escaped value.
|
||||
*/
|
||||
public function js_value() {
|
||||
$value = $this->value();
|
||||
$value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this );
|
||||
|
||||
if ( is_string( $value ) )
|
||||
return html_entity_decode( $value, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
Reference in New Issue
Block a user