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_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
|
|
|
// Sanitie colors. |
75
|
|
|
$value['start']['color'] = ( ! isset( $value['start']['color'] ) ) ? '' : esc_attr( $value['start']['color'] ); |
76
|
|
|
$value['end']['color'] = ( ! isset( $value['end']['color'] ) ) ? '' : esc_attr( $value['end']['color'] ); |
77
|
|
|
|
78
|
|
|
// Sanitize positions. |
79
|
|
|
$value['start']['position'] = ( ! isset( $value['start']['position'] ) ) ? 0 : (int) $value['start']['position']; |
80
|
|
|
$value['start']['position'] = ( 0 > $value['start']['position'] ) ? 0 : $value['start']['position']; |
81
|
|
|
$value['start']['position'] = ( 100 < $value['start']['position'] ) ? 100 : $value['start']['position']; |
82
|
|
|
$value['end']['position'] = ( ! isset( $value['end']['position'] ) ) ? 0 : (int) $value['end']['position']; |
83
|
|
|
$value['end']['position'] = ( 0 > $value['end']['position'] ) ? 0 : $value['end']['position']; |
84
|
|
|
$value['end']['position'] = ( 100 < $value['end']['position'] ) ? 100 : $value['end']['position']; |
85
|
|
|
|
86
|
|
|
// Sanitize angle. |
87
|
|
|
$value['angle'] = ( ! isset( $value['angle'] ) ) ? 0 : (int) $value['angle']; |
88
|
|
|
$value['angle'] = ( -90 > $value['angle'] ) ? -90 : $value['angle']; |
89
|
|
|
$value['angle'] = ( 90 < $value['angle'] ) ? 90 : $value['angle']; |
90
|
|
|
|
91
|
|
|
// Sanitize the type. |
92
|
|
|
$value['type'] = ( ! isset( $value['type'] ) || 'linear' !== $value['type'] || 'radial' !== $value['type'] ) ? 'linear' : $value['type']; |
93
|
|
|
|
94
|
|
|
return $value; |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.