mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-26 02:57:45 +01:00
0860bb2771
Prior to about 2013, many class methods lacked even access modifiers which made the `@access` notations that much more useful. Now that we've gotten to a point where the codebase is more mature from a maintenance perspective and we can finally remove these notations. Notable exceptions to this change include standalone functions notated as private as well as some classes still considered to represent "private" APIs. See #41452. Built from https://develop.svn.wordpress.org/trunk@41162 git-svn-id: http://core.svn.wordpress.org/trunk@41002 1a063a9b-81f0-0310-95a4-ce76da25c4cd
121 lines
2.7 KiB
PHP
121 lines
2.7 KiB
PHP
<?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 {
|
|
/**
|
|
* Type.
|
|
*
|
|
* @var string
|
|
*/
|
|
public $type = 'color';
|
|
|
|
/**
|
|
* Statuses.
|
|
*
|
|
* @var array
|
|
*/
|
|
public $statuses;
|
|
|
|
/**
|
|
* Mode.
|
|
*
|
|
* @since 4.7.0
|
|
* @var string
|
|
*/
|
|
public $mode = 'full';
|
|
|
|
/**
|
|
* 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;
|
|
$this->json['mode'] = $this->mode;
|
|
}
|
|
|
|
/**
|
|
* 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() {
|
|
?>
|
|
<# var defaultValue = '#RRGGBB', defaultValueAttr = '',
|
|
isHueSlider = data.mode === 'hue';
|
|
|
|
if ( data.defaultValue && ! isHueSlider ) {
|
|
if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
|
|
defaultValue = '#' + data.defaultValue;
|
|
} else {
|
|
defaultValue = data.defaultValue;
|
|
}
|
|
defaultValueAttr = ' 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">
|
|
<# if ( isHueSlider ) { #>
|
|
<input class="color-picker-hue" type="text" data-type="hue" />
|
|
<# } else { #>
|
|
<input class="color-picker-hex" type="text" maxlength="7" placeholder="{{ defaultValue }}" {{ defaultValueAttr }} />
|
|
<# } #>
|
|
</div>
|
|
</label>
|
|
<?php
|
|
}
|
|
}
|