Kirki_Field_Radio   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set_type() 0 9 2
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_Radio extends Kirki_Field {
16
17
	/**
18
	 * Whitelisting for backwards-compatibility.
19
	 *
20
	 * @access protected
21
	 * @var string
22
	 */
23
	protected $mode = '';
24
25
	/**
26
	 * Sets the control type.
27
	 *
28
	 * @access protected
29
	 */
30
	protected function set_type() {
31
		$this->type = 'kirki-radio';
32
33
		// Tweaks for backwards-compatibility:
34
		// Prior to version 0.8 radio-buttonset & radio-image were part of the radio control.
35
		if ( in_array( $this->mode, array( 'buttonset', 'image' ), true ) ) {
36
			/* translators: %1$s represents the field ID where the error occurs. %2%s is buttonset/image. */
37
			_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Error in field %1$s. The "mode" argument has been deprecated since Kirki v0.8. Use the "radio-%2$s" type instead.', 'kirki' ), esc_html( $this->settings ), esc_html( $this->mode ) ), '3.0.10' );
38
			$this->type = 'radio-' . $this->mode;
39
		}
40
	}
41
42
	/**
43
	 * Sets the $sanitize_callback
44
	 *
45
	 * @access protected
46
	 */
47
	protected function set_sanitize_callback() {
48
49
		// If a custom sanitize_callback has been defined,
50
		// then we don't need to proceed any further.
51
		if ( ! empty( $this->sanitize_callback ) ) {
52
			return;
53
		}
54
		$this->sanitize_callback = 'sanitize_text_field';
55
	}
56
}
57