Completed
Push — develop ( 1e023b...a029d1 )
by Aristeides
15:30 queued 07:04
created

Kirki_Field_Spacing::sanitize_value()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 9.6666
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_Spacing extends Kirki_Field_Number {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
24
		$this->type = 'kirki-dimensions';
25
26
	}
27
28
	/**
29
	 * Sets the $sanitize_callback.
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_sanitize_callback() {
34
35
		// If a custom sanitize_callback has been defined,
36
		// then we don't need to proceed any further.
37
		if ( ! empty( $this->sanitize_callback ) ) {
38
			return;
39
		}
40
		$this->sanitize_callback = array( $this, 'sanitize_value' );
41
42
	}
43
44
	/**
45
	 * Sanitizes the value.
46
	 *
47
	 * @access public
48
	 * @param array $value The value.
49
	 * @return array
50
	 */
51
	public function sanitize_value( $value ) {
52
53
		// Sanitize each sub-value separately.
54
		foreach ( $value as $key => $sub_value ) {
55
			$value[ $key ] = Kirki_Sanitize_Values::css_dimension( $sub_value );
56
		}
57
		return $value;
58
59
	}
60
61
	/**
62
	 * Sets the $js_vars.
63
	 * Currentlly postMessage does not work with spacing fields
64
	 * so we have to force using the `refresh` mode.
65
	 *
66
	 * @access protected
67
	 */
68
	protected function set_js_vars() {
69
		$this->js_vars   = array();
70
		$this->transport = 'refresh';
71
	}
72
73
	/**
74
	 * Set the choices.
75
	 * Adds a pseudo-element "controls" that helps with the JS API.
76
	 *
77
	 * @access protected
78
	 */
79
	protected function set_choices() {
80
81
		$default_args = array(
82
			'controls' => array(
83
				'top'    => ( isset( $this->default['top'] ) ),
84
				'bottom' => ( isset( $this->default['top'] ) ),
85
				'left'   => ( isset( $this->default['top'] ) ),
86
				'right'  => ( isset( $this->default['top'] ) ),
87
			),
88
			'labels' => apply_filters( 'kirki/' . $this->kirki_config . '/l10n', array(
89
				'top'    => esc_attr__( 'Top', 'kirki' ),
90
				'bottom' => esc_attr__( 'Bottom', 'kirki' ),
91
				'left'   => esc_attr__( 'Left', 'kirki' ),
92
				'right'  => esc_attr__( 'Right', 'kirki' ),
93
			) ),
94
		);
95
96
		$this->choices = wp_parse_args( $this->choices, $default_args );
97
98
	}
99
}
100