3 * Customize API: WP_Customize_Color_Control class
6 * @subpackage Customize
11 * Customize Color Control class.
15 * @see WP_Customize_Control
17 class WP_Customize_Color_Control extends WP_Customize_Control {
24 public $type = 'color';
41 public $mode = 'full';
47 * @uses WP_Customize_Control::__construct()
49 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
50 * @param string $id Control ID.
51 * @param array $args Optional. Arguments to override class property defaults.
53 public function __construct( $manager, $id, $args = array() ) {
54 $this->statuses = array( '' => __('Default') );
55 parent::__construct( $manager, $id, $args );
59 * Enqueue scripts/styles for the color picker.
63 public function enqueue() {
64 wp_enqueue_script( 'wp-color-picker' );
65 wp_enqueue_style( 'wp-color-picker' );
69 * Refresh the parameters passed to the JavaScript via JSON.
72 * @uses WP_Customize_Control::to_json()
74 public function to_json() {
76 $this->json['statuses'] = $this->statuses;
77 $this->json['defaultValue'] = $this->setting->default;
78 $this->json['mode'] = $this->mode;
82 * Don't render the control content from PHP, as it's rendered via JS on load.
86 public function render_content() {}
89 * Render a JS template for the content of the color picker control.
93 public function content_template() {
95 <# var defaultValue = '',
96 isHueSlider = data.mode === 'hue';
98 if ( data.defaultValue && ! isHueSlider ) {
99 if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
100 defaultValue = '#' + data.defaultValue;
102 defaultValue = data.defaultValue;
104 defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
107 <# if ( data.label ) { #>
108 <span class="customize-control-title">{{{ data.label }}}</span>
110 <# if ( data.description ) { #>
111 <span class="description customize-control-description">{{{ data.description }}}</span>
113 <div class="customize-control-content">
114 <# if ( isHueSlider ) { #>
115 <input class="color-picker-hue" type="text" data-type="hue" />
117 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />