Kirki_Field_Dimensions::set_choices()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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_Dimensions extends Kirki_Field {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
		$this->type = 'kirki-dimensions';
24
	}
25
26
	/**
27
	 * Sets the $sanitize_callback.
28
	 *
29
	 * @access protected
30
	 */
31
	protected function set_sanitize_callback() {
32
33
		// If a custom sanitize_callback has been defined,
34
		// then we don't need to proceed any further.
35
		if ( ! empty( $this->sanitize_callback ) ) {
36
			return;
37
		}
38
		$this->sanitize_callback = array( $this, 'sanitize' );
39
	}
40
41
	/**
42
	 * Sanitizes the value.
43
	 *
44
	 * @access public
45
	 * @param array $value The value.
46
	 * @return array
47
	 */
48
	public function sanitize( $value ) {
49
50
		// Sanitize each sub-value separately.
51
		foreach ( $value as $key => $sub_value ) {
52
			$value[ $key ] = sanitize_text_field( $sub_value );
53
		}
54
		return $value;
55
	}
56
57
	/**
58
	 * Set the choices.
59
	 * Adds a pseudo-element "controls" that helps with the JS API.
60
	 *
61
	 * @access protected
62
	 */
63
	protected function set_choices() {
64
		$this->choices['controls'] = array();
65
		if ( is_array( $this->default ) ) {
66
			foreach ( $this->default as $key => $value ) {
67
				$this->choices['controls'][ $key ] = true;
68
			}
69
		}
70
	}
71
}
72