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 {
22 public $type = 'color';
34 * @uses WP_Customize_Control::__construct()
36 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
37 * @param string $id Control ID.
38 * @param array $args Optional. Arguments to override class property defaults.
40 public function __construct( $manager, $id, $args = array() ) {
41 $this->statuses = array( '' => __('Default') );
42 parent::__construct( $manager, $id, $args );
46 * Enqueue scripts/styles for the color picker.
50 public function enqueue() {
51 wp_enqueue_script( 'wp-color-picker' );
52 wp_enqueue_style( 'wp-color-picker' );
56 * Refresh the parameters passed to the JavaScript via JSON.
59 * @uses WP_Customize_Control::to_json()
61 public function to_json() {
63 $this->json['statuses'] = $this->statuses;
64 $this->json['defaultValue'] = $this->setting->default;
68 * Don't render the control content from PHP, as it's rendered via JS on load.
72 public function render_content() {}
75 * Render a JS template for the content of the color picker control.
79 public function content_template() {
81 <# var defaultValue = '';
82 if ( data.defaultValue ) {
83 if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
84 defaultValue = '#' + data.defaultValue;
86 defaultValue = data.defaultValue;
88 defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
91 <# if ( data.label ) { #>
92 <span class="customize-control-title">{{{ data.label }}}</span>
94 <# if ( data.description ) { #>
95 <span class="description customize-control-description">{{{ data.description }}}</span>
97 <div class="customize-control-content">
98 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />