WP_Customize_Color_Control

Customize Color Control class.

Defined (1)

The class is defined in the following location(s).

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