PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.3
Elementor Website Builder – more than just a page builder v3.2.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / settings / controls.php

controls.php in Elementor Website Builder – more than just a page builder 3.2.3, at includes/settings/controls.php

284 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 /**
9 * Elementor settings controls.
10 *
11 * Elementor settings controls handler class responsible for creating the final
12 * HTML for various input field types used in Elementor settings pages.
13 *
14 * @since 1.0.0
15 */
16 class Settings_Controls {
17
18 /**
19 * Render settings control.
20 *
21 * Generates the final HTML on the frontend for any given field based on
22 * the field type (text, select, checkbox, raw HTML, etc.).
23 *
24 * @since 1.0.0
25 * @access public
26 * @static
27 *
28 * @param array $field Optional. Field data. Default is an empty array.
29 */
30 public static function render( $field = [] ) {
31 if ( empty( $field ) || empty( $field['id'] ) ) {
32 return;
33 }
34
35 $defaults = [
36 'type' => '',
37 'attributes' => [],
38 'std' => '',
39 'desc' => '',
40 ];
41
42 $field = array_merge( $defaults, $field );
43
44 $method_name = $field['type'];
45
46 if ( ! method_exists( __CLASS__, $method_name ) ) {
47 $method_name = 'text';
48 }
49
50 self::$method_name( $field );
51 }
52
53 /**
54 * Render text control.
55 *
56 * Generates the final HTML for text controls.
57 *
58 * @since 2.0.0
59 * @access private
60 * @static
61 *
62 * @param array $field Field data.
63 */
64 private static function text( array $field ) {
65 if ( empty( $field['attributes']['class'] ) ) {
66 $field['attributes']['class'] = 'regular-text';
67 }
68
69 $attributes = Utils::render_html_attributes( $field['attributes'] );
70 ?>
71 <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( get_option( $field['id'], $field['std'] ) ); ?>" <?php echo $attributes; ?>/>
72 <?php
73 if ( ! empty( $field['sub_desc'] ) ) :
74 echo $field['sub_desc'];
75 endif;
76 ?>
77 <?php if ( ! empty( $field['desc'] ) ) : ?>
78 <p class="description"><?php echo $field['desc']; ?></p>
79 <?php
80 endif;
81 }
82
83 /**
84 * Render checkbox control.
85 *
86 * Generates the final HTML for checkbox controls.
87 *
88 * @since 2.0.0
89 * @access private
90 * @static
91 *
92 * @param array $field Field data.
93 */
94 private static function checkbox( array $field ) {
95 ?>
96 <label>
97 <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 $field['value']; ?>"<?php checked( $field['value'], get_option( $field['id'], $field['std'] ) ); ?> />
98 <?php
99 if ( ! empty( $field['sub_desc'] ) ) :
100 echo $field['sub_desc'];
101 endif;
102 ?>
103 </label>
104 <?php if ( ! empty( $field['desc'] ) ) : ?>
105 <p class="description"><?php echo $field['desc']; ?></p>
106 <?php
107 endif;
108 }
109
110 /**
111 * Render checkbox list control.
112 *
113 * Generates the final HTML for checkbox list controls.
114 *
115 * @since 2.0.0
116 * @access private
117 * @static
118 *
119 * @param array $field Field data.
120 */
121 private static function checkbox_list( array $field ) {
122 $old_value = get_option( $field['id'], $field['std'] );
123 if ( ! is_array( $old_value ) ) {
124 $old_value = [];
125 }
126
127 foreach ( $field['options'] as $option_key => $option_value ) :
128 ?>
129 <label>
130 <input type="checkbox" name="<?php echo esc_attr( $field['id'] ); ?>[]" value="<?php echo esc_attr( $option_key ); ?>"<?php checked( in_array( $option_key, $old_value ), true ); ?> />
131 <?php echo $option_value; ?>
132 </label><br />
133 <?php endforeach; ?>
134 <?php if ( ! empty( $field['desc'] ) ) : ?>
135 <p class="description"><?php echo $field['desc']; ?></p>
136 <?php
137 endif;
138 }
139
140 /**
141 * Render select control.
142 *
143 * Generates the final HTML for select controls.
144 *
145 * @since 2.0.0
146 * @access private
147 * @static
148 *
149 * @param array $field Field data.
150 */
151 private static function select( array $field ) {
152 $old_value = get_option( $field['id'], $field['std'] );
153 ?>
154 <select name="<?php echo esc_attr( $field['id'] ); ?>">
155 <?php if ( ! empty( $field['show_select'] ) ) : ?>
156 <option value=""> <?php echo __( 'Select', 'elementor' ); ?> </option>
157 <?php endif; ?>
158
159 <?php foreach ( $field['options'] as $value => $label ) : ?>
160 <option value="<?php echo esc_attr( $value ); ?>"<?php selected( $value, $old_value ); ?>><?php echo $label; ?></option>
161 <?php endforeach; ?>
162 </select>
163
164 <?php if ( ! empty( $field['desc'] ) ) : ?>
165 <p class="description"><?php echo $field['desc']; ?></p>
166 <?php
167 endif;
168 }
169
170 /**
171 * Render checkbox list control for CPT.
172 *
173 * Generates the final HTML for checkbox list controls populated with Custom Post Types.
174 *
175 * @since 2.0.0
176 * @access private
177 * @static
178 *
179 * @param array $field Field data.
180 */
181 private static function checkbox_list_cpt( array $field ) {
182 $defaults = [
183 'exclude' => [],
184 ];
185 $field = array_merge( $defaults, $field );
186
187 $post_types_objects = get_post_types(
188 [
189 'public' => true,
190 ], 'objects'
191 );
192
193 /**
194 * Filters the list of post type objects used by Elementor.
195 *
196 * @since 2.8.0
197 *
198 * @param array $post_types_objects List of post type objects used by Elementor.
199 */
200 $post_types_objects = apply_filters( 'elementor/settings/controls/checkbox_list_cpt/post_type_objects', $post_types_objects );
201
202 $field['options'] = [];
203 foreach ( $post_types_objects as $cpt_slug => $post_type ) {
204 if ( in_array( $cpt_slug, $field['exclude'], true ) ) {
205 continue;
206 }
207
208 $field['options'][ $cpt_slug ] = $post_type->labels->name;
209 }
210
211 self::checkbox_list( $field );
212 }
213
214 /**
215 * Render checkbox list control for user roles.
216 *
217 * Generates the final HTML for checkbox list controls populated with user roles.
218 *
219 * @since 2.0.0
220 * @access private
221 * @static
222 *
223 * @param array $field Field data.
224 */
225 private static function checkbox_list_roles( array $field ) {
226 $defaults = [
227 'exclude' => [],
228 ];
229 $field = array_merge( $defaults, $field );
230
231 $field['options'] = [];
232 $roles = get_editable_roles();
233
234 if ( is_multisite() ) {
235 $roles = [
236 'super_admin' => [
237 'name' => __( 'Super Admin', 'elementor' ),
238 ],
239 ] + $roles;
240 }
241
242 foreach ( $roles as $role_slug => $role_data ) {
243 if ( in_array( $role_slug, $field['exclude'] ) ) {
244 continue;
245 }
246
247 $field['options'][ $role_slug ] = $role_data['name'];
248 }
249
250 self::checkbox_list( $field );
251 }
252
253 /**
254 * Render raw HTML control.
255 *
256 * Generates the final HTML for raw HTML controls.
257 *
258 * @since 2.0.0
259 * @access private
260 * @static
261 *
262 * @param array $field Field data.
263 */
264 private static function raw_html( array $field ) {
265 if ( empty( $field['html'] ) ) {
266 return;
267 }
268 ?>
269 <div id="<?php echo $field['id']; ?>">
270
271 <div><?php echo $field['html']; ?></div>
272 <?php
273 if ( ! empty( $field['sub_desc'] ) ) :
274 echo $field['sub_desc'];
275 endif;
276 ?>
277 <?php if ( ! empty( $field['desc'] ) ) : ?>
278 <p class="description"><?php echo $field['desc']; ?></p>
279 <?php endif; ?>
280 </div>
281 <?php
282 }
283 }
284