class-ld-settings-fields-input-select.php
3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* LearnDash Input and Select Settings Field.
*
* @since 3.0.0
* @package LearnDash\Settings\Field
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( class_exists( 'LearnDash_Settings_Fields' ) ) && ( ! class_exists( 'LearnDash_Settings_Fields_Input_Select' ) ) ) {
/**
* Class LearnDash Input and Select Settings Field.
*
* @since 3.0.0
* @uses LearnDash_Settings_Fields
*/
class LearnDash_Settings_Fields_Input_Select extends LearnDash_Settings_Fields {
/**
* Public constructor for class
*
* @since 3.0.0
*/
public function __construct() {
$this->field_type = 'input-select';
parent::__construct();
}
/**
* Function to crete the settings field.
*
* @since 3.0.0
*
* @param array $field_args An array of field arguments used to process the output.
*
* @return void
*/
public function create_section_field( $field_args = array() ) {
/** This filter is documented in includes/settings/settings-fields/class-ld-settings-fields-checkbox-switch.php */
$field_args = apply_filters( 'learndash_settings_field', $field_args );
/** This filter is documented in includes/settings/settings-fields/class-ld-settings-fields-checkbox-switch.php */
$html = apply_filters( 'learndash_settings_field_html_before', '', $field_args );
$html .= '<input autocomplete="off" ';
$html .= $this->get_field_attribute_type( $field_args );
$html .= $this->get_field_attribute_name( $field_args );
$html .= $this->get_field_attribute_id( $field_args );
$html .= $this->get_field_attribute_class( $field_args );
$html .= $this->get_field_attribute_placeholder( $field_args );
$html .= $this->get_field_attribute_misc( $field_args );
$html .= $this->get_field_attribute_required( $field_args );
if ( isset( $field_args['value'] ) ) {
$html .= ' value="' . esc_attr( $field_args['value'] ) . '" ';
} else {
$html .= ' value="" ';
}
$html .= ' />';
if ( ( isset( $field_args['options'] ) ) && ( ! empty( $field_args['options'] ) ) ) {
$html .= '<span class="ld-select">';
$html .= '<select autocomplete="off" ';
$html .= $this->get_field_attribute_type( $field_args );
$html .= $this->get_field_attribute_name( $field_args );
$html .= $this->get_field_attribute_id( $field_args );
$html .= $this->get_field_attribute_class( $field_args );
$html .= $this->get_field_attribute_misc( $field_args );
$html .= $this->get_field_attribute_required( $field_args );
$html .= ' >';
foreach ( $field_args['options'] as $option_key => $option_label ) {
$html .= '<option value="' . esc_attr( $option_key ) . '" ' . selected( $option_key, $field_args['value'], false ) . '>' . wp_kses_post( $option_label ) . '</option>';
}
$html .= '</select>';
$html .= '</span>';
}
/** This filter is documented in includes/settings/settings-fields/class-ld-settings-fields-checkbox-switch.php */
$html = apply_filters( 'learndash_settings_field_html_after', $html, $field_args );
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML
}
}
}
add_action(
'learndash_settings_sections_fields_init',
function() {
LearnDash_Settings_Fields_Input_Select::add_field_instance( 'select' );
}
);