Completed
Push — develop ( 9ec08a...223365 )
by Aristeides
04:37 queued 02:19
created

Kirki_Field_Select::set_default()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
24
		$this->type = 'kirki-select';
25
26
	}
27
28
	/**
29
	 * Sets the $multiple
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_multiple() {
34
35
		$this->multiple = absint( $this->multiple );
36
37
	}
38
39
	/**
40
	 * Sets the $sanitize_callback
41
	 *
42
	 * @access protected
43
	 */
44
	protected function set_sanitize_callback() {
45
46
		// If a custom sanitize_callback has been defined,
47
		// then we don't need to proceed any further.
48
		if ( ! empty( $this->sanitize_callback ) ) {
49
			return;
50
		}
51
		$this->sanitize_callback = array( $this, 'sanitize' );
52
53
	}
54
55
	/**
56
	 * Sanitizes select control values.
57
	 *
58
	 * @since 2.2.8
59
	 * @access public
60
	 * @param array $value The value.
61
	 * @return string|array
62
	 */
63
	public function sanitize( $value ) {
64
65
		if ( is_array( $value ) ) {
66
			foreach ( $value as $key => $subvalue ) {
67
				$value[ $key ] = esc_attr( $subvalue );
68
			}
69
			return $value;
70
		}
71
		return esc_attr( $value );
72
73
	}
74
75
	/**
76
	 * Sets the default value.
77
	 *
78
	 * @access protected
79
	 * @since 2.4.0
80
	 */
81
	protected function set_default() {
82
83
		if ( 1 < $this->multiple && ! is_array( $this->default ) ) {
84
			$this->default = array( $this->default );
85
		}
86
	}
87
}
88