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:
Daryl Koopersmith
2012-05-26 18:44:31 +00:00
parent da056976ea
commit 771ca21787
7 changed files with 101 additions and 74 deletions
@@ -483,7 +483,7 @@ function twentyeleven_customize_register( $wp_customize ) {
$wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array(
'default' => twentyeleven_get_default_link_color( $options['color_scheme'] ),
'type' => 'option',
'sanitize_callback' => 'twentyeleven_sanitize_hexcolor',
'sanitize_callback' => 'sanitize_hex_color',
'capability' => 'edit_theme_options',
) );
@@ -519,17 +519,6 @@ function twentyeleven_customize_register( $wp_customize ) {
}
add_action( 'customize_register', 'twentyeleven_customize_register' );
/**
* Sanitize user input hex color value
*
* @uses sanitize_hexcolor()
* @param $color string
* @return string sanitized with prefixed # character
*/
function twentyeleven_sanitize_hexcolor( $color ) {
return '#' . sanitize_hexcolor( $color );
}
/**
* Bind JS handlers to make Theme Customizer preview reload changes asynchronously.
* Used with blogname and blogdescription.