Kirki_Field_Multicheck   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set_type() 0 2 1
A sanitize() 0 3 3
A set_sanitize_callback() 0 8 2
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_Multicheck extends Kirki_Field {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
		$this->type = 'kirki-multicheck';
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
	 * The sanitize method that will be used as a falback
43
	 *
44
	 * @param string|array $value The control's value.
45
	 */
46
	public function sanitize( $value ) {
47
		$value = ( ! is_array( $value ) ) ? explode( ',', $value ) : $value;
48
		return ( ! empty( $value ) ) ? array_map( 'sanitize_text_field', $value ) : array();
49
	}
50
}
51