WordPress 4.4
[autoinstalls/wordpress.git] / wp-includes / customize / class-wp-customize-color-control.php
1 <?php
2 /**
3  * Customize API: WP_Customize_Color_Control class
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 4.4.0
8  */
9
10 /**
11  * Customize Color Control class.
12  *
13  * @since 3.4.0
14  *
15  * @see WP_Customize_Control
16  */
17 class WP_Customize_Color_Control extends WP_Customize_Control {
18         /**
19          * @access public
20          * @var string
21          */
22         public $type = 'color';
23
24         /**
25          * @access public
26          * @var array
27          */
28         public $statuses;
29
30         /**
31          * Constructor.
32          *
33          * @since 3.4.0
34          * @uses WP_Customize_Control::__construct()
35          *
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.
39          */
40         public function __construct( $manager, $id, $args = array() ) {
41                 $this->statuses = array( '' => __('Default') );
42                 parent::__construct( $manager, $id, $args );
43         }
44
45         /**
46          * Enqueue scripts/styles for the color picker.
47          *
48          * @since 3.4.0
49          */
50         public function enqueue() {
51                 wp_enqueue_script( 'wp-color-picker' );
52                 wp_enqueue_style( 'wp-color-picker' );
53         }
54
55         /**
56          * Refresh the parameters passed to the JavaScript via JSON.
57          *
58          * @since 3.4.0
59          * @uses WP_Customize_Control::to_json()
60          */
61         public function to_json() {
62                 parent::to_json();
63                 $this->json['statuses'] = $this->statuses;
64                 $this->json['defaultValue'] = $this->setting->default;
65         }
66
67         /**
68          * Don't render the control content from PHP, as it's rendered via JS on load.
69          *
70          * @since 3.4.0
71          */
72         public function render_content() {}
73
74         /**
75          * Render a JS template for the content of the color picker control.
76          *
77          * @since 4.1.0
78          */
79         public function content_template() {
80                 ?>
81                 <# var defaultValue = '';
82                 if ( data.defaultValue ) {
83                         if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
84                                 defaultValue = '#' + data.defaultValue;
85                         } else {
86                                 defaultValue = data.defaultValue;
87                         }
88                         defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
89                 } #>
90                 <label>
91                         <# if ( data.label ) { #>
92                                 <span class="customize-control-title">{{{ data.label }}}</span>
93                         <# } #>
94                         <# if ( data.description ) { #>
95                                 <span class="description customize-control-description">{{{ data.description }}}</span>
96                         <# } #>
97                         <div class="customize-control-content">
98                                 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />
99                         </div>
100                 </label>
101                 <?php
102         }
103 }