Completed
Push — develop ( 38967a...dc04ac )
by Aristeides
02:42
created

Kirki_Field_Checkbox::sanitize()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
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) 2017, 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_Checkbox extends Kirki_Field {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
24
		$this->type = 'checkbox';
25
26
	}
27
28
	/**
29
	 * Sets the $sanitize_callback.
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_sanitize_callback() {
34
35
		if ( ! $this->sanitize_callback ) {
36
			$this->sanitize_callback = array( $this, 'sanitize' );
37
		}
38
39
	}
40
41
	/**
42
	 * Sanitizes checkbox values.
43
	 *
44
	 * @access public
45
	 * @param boolean|integer|string|null $value The checkbox value.
46
	 * @return bool
47
	 */
48
	public function sanitize( $value = null ) {
49
50
		if ( '0' === $value || 'false' === $value ) {
51
			return false;
52
		}
53
54
		return (bool) $value;
55
56
	}
57
58
	/**
59
	 * Sets the default value.
60
	 *
61
	 * @access protected
62
	 */
63
	protected function set_default() {
64
65
		$this->default = (bool) ( 1 === $this->default || '1' === $this->default || true === $this->default || 'true' === $this->default || 'on' === $this->default );
66
67
	}
68
}
69