/var/www/html_us/wp-content/plugins/elementor/includes/settings/controls.php


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
namespace Elementor;

if ( ! 
defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly.
}

/**
 * Elementor settings controls.
 *
 * Elementor settings controls handler class responsible for creating the final
 * HTML for various input field types used in Elementor settings pages.
 *
 * @since 1.0.0
 */
class Settings_Controls {

    
/**
     * Render settings control.
     *
     * Generates the final HTML on the frontend for any given field based on
     * the field type (text, select, checkbox, raw HTML, etc.).
     *
     * @since 1.0.0
     * @access public
     * @static
     *
     * @param array $field Optional. Field data. Default is an empty array.
     */
    
public static function render$field = [] ) {
        if ( empty( 
$field ) || empty( $field['id'] ) ) {
            return;
        }

        
$defaults = [
            
'type' => '',
            
'attributes' => [],
            
'std' => '',
            
'desc' => '',
        ];

        
$field array_merge$defaults$field );

        
$method_name $field['type'];

        if ( ! 
method_exists__CLASS__$method_name ) ) {
            
$method_name 'text';
        }

        
self::$method_name$field );
    }

    
/**
     * Render text control.
     *
     * Generates the final HTML for text controls.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function text( array $field ) {
        if ( empty( 
$field['attributes']['class'] ) ) {
            
$field['attributes']['class'] = 'regular-text';
        }

        
?>
        <input type="<?php echo esc_attr$field['type'] ); ?>" id="<?php echo esc_attr$field['id'] ); ?>" name="<?php echo esc_attr$field['id'] ); ?>" value="<?php echo esc_attrget_option$field['id'], $field['std'] ) ); ?><?php Utils::print_html_attributes$field['attributes'] ); ?>/>
        <?php
        
if ( ! empty( $field['sub_desc'] ) ) :
            echo 
wp_kses_post$field['sub_desc'] );
        endif;
        
?>
        <?php if ( ! empty( $field['desc'] ) ) : ?>
            <p class="description"><?php echo wp_kses_post$field['desc'] ); ?></p>
            <?php
        
endif;
    }

    
/**
     * Render checkbox control.
     *
     * Generates the final HTML for checkbox controls.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function checkbox( array $field ) {
        
?>
        <label>
            <input type="<?php echo esc_attr$field['type'] ); ?>" id="<?php echo esc_attr$field['id'] ); ?>" name="<?php echo esc_attr$field['id'] ); ?>" value="<?php echo esc_attr$field['value'] ); ?>"<?php checked$field['value'], get_option$field['id'], $field['std'] ) ); ?> />
            <?php
            
if ( ! empty( $field['sub_desc'] ) ) :
                echo 
wp_kses_post$field['sub_desc'] );
            endif;
            
?>
        </label>
        <?php if ( ! empty( $field['desc'] ) ) : ?>
            <p class="description"><?php echo wp_kses_post$field['desc'] ); ?></p>
            <?php
        
endif;
    }

    
/**
     * Render checkbox list control.
     *
     * Generates the final HTML for checkbox list controls.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function checkbox_list( array $field ) {
        
$old_value get_option$field['id'], $field['std'] );
        if ( ! 
is_array$old_value ) ) {
            
$old_value = [];
        }

        foreach ( 
$field['options'] as $option_key => $option_value ) :
            
?>
            <label>
                <input type="checkbox" name="<?php echo esc_attr$field['id'] ); ?>[]" value="<?php echo esc_attr$option_key ); ?>"<?php checkedin_array$option_key$old_value ), true ); ?> />
                <?php echo wp_kses_post$option_value ); ?>
            </label><br />
        <?php endforeach; ?>
        <?php if ( ! empty( $field['desc'] ) ) : ?>
            <p class="description"><?php echo wp_kses_post$field['desc'] ); ?></p>
            <?php
        
endif;
    }

    
/**
     * Render select control.
     *
     * Generates the final HTML for select controls.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function select( array $field ) {
        
$old_value get_option$field['id'], $field['std'] );
        
?>
        <select name="<?php echo esc_attr$field['id'] ); ?>">
            <?php if ( ! empty( $field['show_select'] ) ) : ?>
                <option value="">— <?php echo esc_html__'Select''elementor' ); ?> —</option>
            <?php endif; ?>

            <?php foreach ( $field['options'] as $value => $label ) : ?>
                <option value="<?php echo esc_attr$value ); ?>"<?php esc_attrselected$value$old_value ) ); ?>><?php echo esc_html$label ); ?></option>
            <?php endforeach; ?>
        </select>

        <?php if ( ! empty( $field['desc'] ) ) : ?>
            <p class="description"><?php echo wp_kses_post$field['desc'] ); ?></p>
            <?php
        
endif;
    }

    
/**
     * Render checkbox list control for CPT.
     *
     * Generates the final HTML for checkbox list controls populated with Custom Post Types.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function checkbox_list_cpt( array $field ) {
        
$defaults = [
            
'exclude' => [],
        ];
        
$field array_merge$defaults$field );

        
$post_types_objects get_post_types(
            [
                
'public' => true,
            ], 
'objects'
        
);

        
/**
         * Filters the list of post type objects used by Elementor.
         *
         * @since 2.8.0
         *
         * @param array $post_types_objects List of post type objects used by Elementor.
         */
        
$post_types_objects apply_filters'elementor/settings/controls/checkbox_list_cpt/post_type_objects'$post_types_objects );

        
$field['options'] = [];
        foreach ( 
$post_types_objects as $cpt_slug => $post_type ) {
            if ( 
in_array$cpt_slug$field['exclude'], true ) ) {
                continue;
            }

            
$field['options'][ $cpt_slug ] = $post_type->labels->name;
        }

        
self::checkbox_list$field );
    }

    
/**
     * Render checkbox list control for user roles.
     *
     * Generates the final HTML for checkbox list controls populated with user roles.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function checkbox_list_roles( array $field ) {
        
$defaults = [
            
'exclude' => [],
        ];
        
$field array_merge$defaults$field );

        
$field['options'] = [];
        
$roles get_editable_roles();

        if ( 
is_multisite() ) {
            
$roles = [
                
'super_admin' => [
                    
'name' => esc_html__'Super Admin''elementor' ),
                ],
            ] + 
$roles;
        }

        foreach ( 
$roles as $role_slug => $role_data ) {
            if ( 
in_array$role_slug$field['exclude'] ) ) {
                continue;
            }

            
$field['options'][ $role_slug ] = $role_data['name'];
        }

        
self::checkbox_list$field );
    }

    
/**
     * Render raw HTML control.
     *
     * Generates the final HTML for raw HTML controls.
     *
     * @since 2.0.0
     * @access private
     * @static
     *
     * @param array $field Field data.
     */
    
private static function raw_html( array $field ) {
        if ( empty( 
$field['html'] ) ) {
            return;
        }
        
?>
        <div id="<?php echo esc_attr$field['id'] ); ?>">

            <?php // PHPCS - This is a Raw HTML control, it is not escaped on purpose. ?>
            <div><?php echo $field['html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
            <?php
            
if ( ! empty( $field['sub_desc'] ) ) :
                echo 
wp_kses_post$field['sub_desc'] );
            endif;
            
?>
            <?php if ( ! empty( $field['desc'] ) ) : ?>
                <p class="description"><?php echo wp_kses_post$field['desc'] ); ?></p>
            <?php endif; ?>
            </div>
        <?php
    
}
}