2015-10-24 20:57:25 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Customize API: WP_Customize_Color_Control class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Customize
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customize Color Control class.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @see WP_Customize_Control
|
|
|
|
*/
|
|
|
|
class WP_Customize_Color_Control extends WP_Customize_Control {
|
|
|
|
/**
|
2016-11-23 07:05:32 +01:00
|
|
|
* Type.
|
|
|
|
*
|
2015-10-24 20:57:25 +02:00
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $type = 'color';
|
|
|
|
|
|
|
|
/**
|
2016-11-23 07:05:32 +01:00
|
|
|
* Statuses.
|
|
|
|
*
|
2015-10-24 20:57:25 +02:00
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $statuses;
|
|
|
|
|
2016-10-26 00:33:30 +02:00
|
|
|
/**
|
2016-11-23 07:05:32 +01:00
|
|
|
* Mode.
|
|
|
|
*
|
|
|
|
* @since 4.7.0
|
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-10-26 00:33:30 +02:00
|
|
|
public $mode = 'full';
|
|
|
|
|
2015-10-24 20:57:25 +02:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
* @uses WP_Customize_Control::__construct()
|
|
|
|
*
|
|
|
|
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
|
|
|
|
* @param string $id Control ID.
|
|
|
|
* @param array $args Optional. Arguments to override class property defaults.
|
|
|
|
*/
|
|
|
|
public function __construct( $manager, $id, $args = array() ) {
|
|
|
|
$this->statuses = array( '' => __('Default') );
|
|
|
|
parent::__construct( $manager, $id, $args );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue scripts/styles for the color picker.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*/
|
|
|
|
public function enqueue() {
|
|
|
|
wp_enqueue_script( 'wp-color-picker' );
|
|
|
|
wp_enqueue_style( 'wp-color-picker' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh the parameters passed to the JavaScript via JSON.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
* @uses WP_Customize_Control::to_json()
|
|
|
|
*/
|
|
|
|
public function to_json() {
|
|
|
|
parent::to_json();
|
|
|
|
$this->json['statuses'] = $this->statuses;
|
|
|
|
$this->json['defaultValue'] = $this->setting->default;
|
2016-10-26 00:33:30 +02:00
|
|
|
$this->json['mode'] = $this->mode;
|
2015-10-24 20:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Don't render the control content from PHP, as it's rendered via JS on load.
|
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*/
|
|
|
|
public function render_content() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a JS template for the content of the color picker control.
|
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
*/
|
|
|
|
public function content_template() {
|
|
|
|
?>
|
2016-10-26 00:33:30 +02:00
|
|
|
<# var defaultValue = '',
|
|
|
|
isHueSlider = data.mode === 'hue';
|
|
|
|
|
|
|
|
if ( data.defaultValue && ! isHueSlider ) {
|
2015-10-24 20:57:25 +02:00
|
|
|
if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
|
|
|
|
defaultValue = '#' + data.defaultValue;
|
|
|
|
} else {
|
|
|
|
defaultValue = data.defaultValue;
|
|
|
|
}
|
|
|
|
defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
|
|
|
|
} #>
|
|
|
|
<label>
|
|
|
|
<# if ( data.label ) { #>
|
|
|
|
<span class="customize-control-title">{{{ data.label }}}</span>
|
|
|
|
<# } #>
|
|
|
|
<# if ( data.description ) { #>
|
|
|
|
<span class="description customize-control-description">{{{ data.description }}}</span>
|
|
|
|
<# } #>
|
|
|
|
<div class="customize-control-content">
|
2016-10-26 00:33:30 +02:00
|
|
|
<# if ( isHueSlider ) { #>
|
|
|
|
<input class="color-picker-hue" type="text" data-type="hue" />
|
|
|
|
<# } else { #>
|
|
|
|
<input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />
|
|
|
|
<# } #>
|
2015-10-24 20:57:25 +02:00
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|