aristath /
kirki
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Override field methods |
||
| 4 | * |
||
| 5 | * @package Kirki |
||
| 6 | * @subpackage Controls |
||
| 7 | * @copyright Copyright (c) 2017, Aristeides Stathopoulos |
||
| 8 | * @license https://opensource.org/licenses/MIT |
||
| 9 | * @since 2.2.7 |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Field overrides. |
||
| 14 | */ |
||
| 15 | class Kirki_Field_Color extends Kirki_Field { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Backwards compatibility. |
||
| 19 | * |
||
| 20 | * @access protected |
||
| 21 | * @var bool |
||
| 22 | */ |
||
| 23 | protected $alpha = false; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Mode (hue) |
||
| 27 | * |
||
| 28 | * @access protected |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $mode = 'full'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Sets the control type. |
||
| 35 | * |
||
| 36 | * @access protected |
||
| 37 | */ |
||
| 38 | protected function set_type() { |
||
| 39 | $this->type = 'kirki-color'; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Sets the $choices |
||
| 44 | * |
||
| 45 | * @access protected |
||
| 46 | */ |
||
| 47 | protected function set_choices() { |
||
| 48 | if ( ! is_array( $this->choices ) ) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 49 | $this->choices = array(); |
||
| 50 | } |
||
| 51 | if ( true === $this->alpha ) { |
||
| 52 | _doing_it_wrong( 'Kirki::add_field', esc_html__( 'Do not use "alpha" as an argument in color controls. Use "choices[alpha]" instead.', 'kirki' ), '3.0.10' ); |
||
| 53 | $this->choices['alpha'] = true; |
||
| 54 | } |
||
| 55 | if ( ! isset( $this->choices['alpha'] ) || true !== $this->choices['alpha'] ) { |
||
| 56 | $this->choices['alpha'] = true; |
||
| 57 | if ( property_exists( $this, 'default' ) && ! empty( $this->default ) && false === strpos( 'rgba', $this->default ) ) { |
||
| 58 | $this->choices['alpha'] = false; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | if ( ( ! isset( $this->choices['mode'] ) ) || ( 'hex' !== $this->choices['mode'] || 'hue' !== $this->choices['mode'] ) ) { |
||
| 63 | $this->choices['mode'] = 'hex'; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Sets the $sanitize_callback |
||
| 69 | * |
||
| 70 | * @access protected |
||
| 71 | */ |
||
| 72 | protected function set_sanitize_callback() { |
||
| 73 | |||
| 74 | // If a custom sanitize_callback has been defined, |
||
| 75 | // then we don't need to proceed any further. |
||
| 76 | if ( ! empty( $this->sanitize_callback ) ) { |
||
| 77 | return; |
||
| 78 | } |
||
| 79 | if ( 'hue' === $this->mode ) { |
||
| 80 | $this->sanitize_callback = 'absint'; |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | $this->sanitize_callback = array( 'Kirki_Sanitize_Values', 'color' ); |
||
| 84 | } |
||
| 85 | } |
||
| 86 |