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_Select extends Kirki_Field { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Use only on select controls. |
||
| 19 | * Defines if this is a multi-select or not. |
||
| 20 | * If value is > 1, then the maximum number of selectable options |
||
| 21 | * is the number defined here. |
||
| 22 | * |
||
| 23 | * @access protected |
||
| 24 | * @var integer |
||
| 25 | */ |
||
| 26 | protected $multiple = 1; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Placeholder text. |
||
| 30 | * |
||
| 31 | * @access protected |
||
| 32 | * @since 3.0.21 |
||
| 33 | * @var string|false |
||
| 34 | */ |
||
| 35 | protected $placeholder = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Sets the control type. |
||
| 39 | * |
||
| 40 | * @access protected |
||
| 41 | */ |
||
| 42 | protected function set_type() { |
||
| 43 | $this->type = 'kirki-select'; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Sets the $multiple |
||
| 48 | * |
||
| 49 | * @access protected |
||
| 50 | */ |
||
| 51 | protected function set_multiple() { |
||
| 52 | $this->multiple = absint( $this->multiple ); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Sets the $sanitize_callback |
||
| 57 | * |
||
| 58 | * @access protected |
||
| 59 | */ |
||
| 60 | protected function set_sanitize_callback() { |
||
| 61 | |||
| 62 | // If a custom sanitize_callback has been defined, |
||
| 63 | // then we don't need to proceed any further. |
||
| 64 | if ( ! empty( $this->sanitize_callback ) ) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | $this->sanitize_callback = array( $this, 'sanitize' ); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Sanitizes select control values. |
||
| 72 | * |
||
| 73 | * @since 2.2.8 |
||
| 74 | * @access public |
||
| 75 | * @param array $value The value. |
||
| 76 | * @return string|array |
||
| 77 | */ |
||
| 78 | public function sanitize( $value ) { |
||
| 79 | if ( is_array( $value ) ) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 80 | foreach ( $value as $key => $subvalue ) { |
||
| 81 | if ( '' !== $subvalue || isset( $this->choices[''] ) ) { |
||
| 82 | $key = sanitize_key( $key ); |
||
| 83 | $value[ $key ] = sanitize_text_field( $subvalue ); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | return $value; |
||
| 87 | } |
||
| 88 | return sanitize_text_field( $value ); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Sets the default value. |
||
| 93 | * |
||
| 94 | * @access protected |
||
| 95 | * @since 3.0.0 |
||
| 96 | */ |
||
| 97 | protected function set_default() { |
||
| 98 | if ( 1 < $this->multiple && ! is_array( $this->default ) ) { |
||
| 99 | $this->default = array( $this->default ); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 |