Kirki_Field_Sortable   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sanitize() 0 13 5
A set_sanitize_callback() 0 2 1
A set_type() 0 2 1
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.3.2
10
 */
11
12
/**
13
 * Field overrides.
14
 */
15
class Kirki_Field_Sortable extends Kirki_Field {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
		$this->type = 'kirki-sortable';
24
	}
25
26
	/**
27
	 * Sets the $sanitize_callback.
28
	 *
29
	 * @access protected
30
	 */
31
	protected function set_sanitize_callback() {
32
		$this->sanitize_callback = array( $this, 'sanitize' );
33
	}
34
35
	/**
36
	 * Sanitizes sortable values.
37
	 *
38
	 * @access public
39
	 * @param array $value The checkbox value.
40
	 * @return array
41
	 */
42
	public function sanitize( $value = array() ) {
43
		if ( is_string( $value ) || is_numeric( $value ) ) {
0 ignored issues
show
introduced by
The condition is_numeric($value) is always false.
Loading history...
44
			return array(
45
				sanitize_text_field( $value ),
46
			);
47
		}
48
		$sanitized_value = array();
49
		foreach ( $value as $sub_value ) {
50
			if ( isset( $this->choices[ $sub_value ] ) ) {
51
				$sanitized_value[] = sanitize_text_field( $sub_value );
52
			}
53
		}
54
		return $sanitized_value;
55
	}
56
}
57