1 | <?php |
||
15 | class Kirki_Field_Gradient extends Kirki_Field { |
||
16 | |||
17 | /** |
||
18 | * Sets the control type. |
||
19 | * |
||
20 | * @access protected |
||
21 | */ |
||
22 | protected function set_type() { |
||
23 | |||
24 | $this->type = 'kirki-gradient'; |
||
25 | |||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Sets the $choices |
||
30 | * |
||
31 | * @access protected |
||
32 | */ |
||
33 | protected function set_choices() { |
||
34 | |||
35 | if ( ! is_array( $this->choices ) ) { |
||
36 | $this->choices = array(); |
||
37 | } |
||
38 | |||
39 | $defaults = array( |
||
40 | 'alpha' => true, |
||
41 | 'direction' => 'top-to-bottom', |
||
42 | ); |
||
43 | $this->choices = wp_parse_args( $this->choices, $defaults ); |
||
44 | |||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Sets the $sanitize_callback. |
||
49 | * |
||
50 | * @access protected |
||
51 | */ |
||
52 | protected function set_sanitize_callback() { |
||
53 | |||
54 | $this->sanitize_callback = array( $this, 'sanitize' ); |
||
55 | |||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Sanitizes checkbox values. |
||
60 | * |
||
61 | * @access public |
||
62 | * @param boolean|integer|string|null $value The checkbox value. |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function sanitize( $value = null ) { |
||
66 | |||
67 | // Make sure value in an array. |
||
68 | $value = ( ! is_array( $value ) ) ? array() : $value; |
||
69 | |||
70 | // Make sure start & end values are arrays. |
||
71 | $value['start'] = ( ! isset( $value['start'] ) ) ? array() : $value['start']; |
||
72 | $value['end'] = ( ! isset( $value['end'] ) ) ? array() : $value['end']; |
||
73 | |||
74 | foreach ( array( 'start', 'end' ) as $context ) { |
||
75 | |||
76 | // Sanitize colors. |
||
77 | if ( ! isset( $value[ $context ]['color'] ) ) { |
||
78 | $value[ $context ]['color'] = ''; |
||
79 | } |
||
80 | $value[ $context ]['color'] = esc_attr( $value[ $context ]['color'] ); |
||
|
|||
81 | |||
82 | // Sanitize positions. |
||
83 | if ( ! isset( $value[ $context ]['position'] ) ) { |
||
84 | $value[ $context ]['position'] = 0; |
||
85 | }; |
||
86 | $value[ $context ]['position'] = (int) $value[ $context ]['position']; |
||
87 | $value[ $context ]['position'] = max( min( $value[ $context ]['position'], 100 ), 0 ); |
||
88 | } |
||
89 | |||
90 | // Sanitize angle. |
||
91 | if ( ! isset( $value['angle'] ) ) { |
||
92 | $value['angle'] = 0; |
||
93 | } |
||
94 | $value['angle'] = (int) $value['angle']; |
||
95 | $value['angle'] = max( min( $value['angle'], 90 ), -90 ) |
||
96 | |||
97 | // Sanitize the type. |
||
98 | $value['type'] = ( ! isset( $value['type'] ) || 'linear' !== $value['type'] || 'radial' !== $value['type'] ) ? 'linear' : $value['type']; |
||
99 | |||
105 |