Completed
Push — develop ( 370152...d94e50 )
by David
03:11
created

Wordlift_Admin_Radio_Input_Element::render()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 23
nc 4
nop 1
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Elements: Radio Input.
4
 *
5
 * Represents an Radio Input text box.
6
 *
7
 * @since      3.13.0
8
 * @package    Wordlift
9
 * @subpackage Wordlift/admin
10
 */
11
12
/**
13
 * Define the {@link Wordlift_Admin_Radio_Input_Element} class.
14
 *
15
 * @since      3.13.0
16
 * @package    Wordlift
17
 * @subpackage Wordlift/admin
18
 */
19
class Wordlift_Admin_Radio_Input_Element implements Wordlift_Admin_Element {
20
21
	/**
22
	 * Output the HTML for an input box type settings_page.
23
	 *
24
	 * @since      3.13.0
25
	 *
26
	 * @param array $args        {
27
	 *                           An array of arguments.
28
	 *
29
	 * @type string $name        The name attribute of the input element. Mandatory.
30
	 * @type string $id          The id attribute of the input element. Optional,
31
	 *                           randomly generated one is used if not supplied.
32
	 * @type string $value       The value of the input element. Optional, defaults
33
	 *                           to empty string.
34
	 * @type string $css_class   The class attribute for the input element. If empty
35
	 *                           string no class attribute will be added. Optional,
36
	 *                           defaults to empty string.
37
	 * @type string $description The description text to be displayed below the element.
38
	 *                           Can include some HTML element. If empty string no
39
	 *                           description will be displayed. Optional, defaults to
40
	 *                           empty string.
41
	 * }
42
	 * @return $this|Wordlift_Admin_Element
43
	 */
44
	public function render( $args ) {
45
46
		/*
47
		 * Parse the arguments and merge with default values.
48
		 * Name intentionally do not have a default as it has to be in SyncEvent
49
		 * with form handling code
50
		 */
51
		$params = wp_parse_args( $args, array(
52
			'id'          => uniqid( 'wl-input-' ),
53
			'value'       => '',
54
			'css_class'   => '',
55
			'description' => '',
56
		) );
57
58
		// Set the readonly and class attributes and the description.
59
		$value       = $params['value'];
60
		$css_class   = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : '';
61
		$description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : '';
62
63
		?>
64
65
		<input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>"
66
		       name="<?php echo esc_attr( $params['name'] ); ?>"
67
		       value="yes" <?php echo $css_class; ?>
68
			<?php checked( $value, 'yes' ); ?> /> Yes
69
		<input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>"
70
		       name="<?php echo esc_attr( $params['name'] ); ?>"
71
		       value="no" <?php echo $css_class; ?>
72
			<?php checked( $value, 'no' ); ?>/> No
73
74
		<?php echo $description; ?>
75
76
		<?php
77
		return $this;
78
	}
79
80
}
81