Completed
Pull Request — master (#1454)
by Aristeides
05:51 queued 02:50
created

Kirki_Field_Switch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set_type() 0 5 1
A set_choices() 0 18 3
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_Switch extends Kirki_Field_Checkbox {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
24
		$this->type = 'kirki-switch';
25
26
	}
27
28
	/**
29
	 * Sets the control choices.
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_choices() {
34
35
		if ( ! is_customize_preview() ) {
36
			return;
37
		}
38
		if ( ! is_array( $this->choices ) ) {
39
			$this->choices = array();
40
		}
41
42
		$this->choices = wp_parse_args(
43
			$this->choices,
44
			array(
45
				'on'    => esc_attr__( 'On', 'kirki' ),
46
				'off'   => esc_attr__( 'Off', 'kirki' ),
47
				'round' => false,
48
			)
49
		);
50
	}
51
}
52