Completed
Push — develop ( f818c0...470152 )
by Aristeides
02:26
created

Kirki_Field_Sortable::sanitize()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 1
dl 0
loc 16
rs 8.8571
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.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
24
		$this->type = 'kirki-sortable';
25
26
	}
27
28
	/**
29
	 * Sets the $sanitize_callback.
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_sanitize_callback() {
34
35
		$this->sanitize_callback = array( $this, 'sanitize' );
36
37
	}
38
39
	/**
40
	 * Sanitizes sortable values.
41
	 *
42
	 * @access public
43
	 * @param array $value The checkbox value.
44
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

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.

Loading history...
45
	 */
46
	public function sanitize( $value = array() ) {
47
48
		if ( is_string( $value ) || is_numeric( $value ) ) {
49
			return array(
50
				esc_attr( $value ),
51
			);
52
		}
53
		$sanitized_value = array();
54
		foreach ( $value as $sub_value ) {
55
			if ( isset( $this->choices[ $sub_value ] ) ) {
56
				$sanitized_value[] = esc_attr( $sub_value );
57
			}
58
		}
59
		return $sanitized_value;
60
61
	}
62
}
63