|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Override field methods |
|
4
|
|
|
* |
|
5
|
|
|
* @package Kirki |
|
6
|
|
|
* @subpackage Controls |
|
7
|
|
|
* @copyright Copyright (c) 2016, Aristeides Stathopoulos |
|
8
|
|
|
* @license http://opensource.org/licenses/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
|
|
|
* Sets the control type. |
|
30
|
|
|
* |
|
31
|
|
|
* @access protected |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function set_type() { |
|
34
|
|
|
|
|
35
|
|
|
$this->type = 'kirki-select'; |
|
36
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Sets the $multiple |
|
41
|
|
|
* |
|
42
|
|
|
* @access protected |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function set_multiple() { |
|
45
|
|
|
|
|
46
|
|
|
$this->multiple = absint( $this->multiple ); |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Sets the $sanitize_callback |
|
52
|
|
|
* |
|
53
|
|
|
* @access protected |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function set_sanitize_callback() { |
|
56
|
|
|
|
|
57
|
|
|
// If a custom sanitize_callback has been defined, |
|
58
|
|
|
// then we don't need to proceed any further. |
|
59
|
|
|
if ( ! empty( $this->sanitize_callback ) ) { |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
$this->sanitize_callback = array( $this, 'sanitize' ); |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Sanitizes select control values. |
|
68
|
|
|
* |
|
69
|
|
|
* @since 2.2.8 |
|
70
|
|
|
* @access public |
|
71
|
|
|
* @param array $value The value. |
|
72
|
|
|
* @return string|array |
|
73
|
|
|
*/ |
|
74
|
|
|
public function sanitize( $value ) { |
|
75
|
|
|
|
|
76
|
|
|
if ( is_array( $value ) ) { |
|
77
|
|
|
foreach ( $value as $key => $subvalue ) { |
|
78
|
|
|
if ( '' !== $subvalue || isset( $this->choices[''] ) ) { |
|
79
|
|
|
$value[ $key ] = esc_attr( $subvalue ); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
return $value; |
|
83
|
|
|
} |
|
84
|
|
|
if ( '' === $value && ! isset( $this->choices[''] ) ) { |
|
85
|
|
|
return esc_attr( $this->default ); |
|
86
|
|
|
} |
|
87
|
|
|
return esc_attr( $value ); |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Sets the default value. |
|
93
|
|
|
* |
|
94
|
|
|
* @access protected |
|
95
|
|
|
* @since 2.4.0 |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function set_default() { |
|
98
|
|
|
|
|
99
|
|
|
if ( 1 < $this->multiple && ! is_array( $this->default ) ) { |
|
100
|
|
|
$this->default = array( $this->default ); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|