PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.4.8
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.4.8
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / admin / class-evf-admin-settings.php
everest-forms / includes / admin Last commit date
builder 2 months ago form-migrator 3 months ago plugin-updates 8 years ago settings 2 months ago views 2 months ago class-evf-admin-addons.php 5 months ago class-evf-admin-assets.php 2 months ago class-evf-admin-builder.php 2 months ago class-evf-admin-dashboard.php 3 months ago class-evf-admin-editor.php 4 years ago class-evf-admin-embed-wizard.php 2 years ago class-evf-admin-entries-table-list.php 2 months ago class-evf-admin-entries.php 2 months ago class-evf-admin-form-templates.php 3 months ago class-evf-admin-forms-table-list.php 5 months ago class-evf-admin-forms.php 5 months ago class-evf-admin-import-export.php 4 years ago class-evf-admin-menus.php 3 months ago class-evf-admin-notices.php 5 months ago class-evf-admin-preview-confirmation.php 1 year ago class-evf-admin-settings.php 3 months ago class-evf-admin-tools.php 2 months ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 2 months ago class-evf-base-list-table.php 5 months ago evf-admin-functions.php 2 months ago
class-evf-admin-settings.php
1259 lines
1 <?php
2 /**
3 * EverestForms Admin Settings Class
4 *
5 * @package EverestForms\Admin
6 * @version 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 if ( ! class_exists( 'EVF_Admin_Settings', false ) ) :
12
13 /**
14 * EVF_Admin_Settings Class.
15 */
16 class EVF_Admin_Settings {
17
18 /**
19 * Setting pages.
20 *
21 * @var array
22 */
23 private static $settings = array();
24
25 /**
26 * Error messages.
27 *
28 * @var array
29 */
30 private static $errors = array();
31
32 /**
33 * Update messages.
34 *
35 * @var array
36 */
37 private static $messages = array();
38
39 /**
40 * Include the settings page classes.
41 */
42 public static function get_settings_pages() {
43
44 $settings = array();
45
46 include_once __DIR__ . '/settings/class-evf-settings-page.php';
47
48 $settings[] = include 'settings/class-evf-settings-general.php';
49 $settings[] = include 'settings/class-evf-settings-security.php';
50 $settings[] = include 'settings/class-evf-settings-email.php';
51 $settings[] = include 'settings/class-evf-settings-integrations.php';
52 $settings[] = include 'settings/class-evf-setting-utilities.php';
53 $settings[] = include 'settings/class-evf-settings-advanced.php';
54
55 // Store settings pages before and after filter so reorder_settings_tabs
56 // can reference them to check has_real_sections().
57 self::$settings = $settings;
58
59 $settings = apply_filters( 'everest_forms_get_settings_pages', $settings );
60
61 self::$settings = $settings;
62
63 add_filter( 'everest_forms_settings_tabs_array', array( __CLASS__, 'reorder_settings_tabs' ), 9999 );
64
65 return $settings;
66 }
67
68 /**
69 * Reorder settings tabs and hide tabs with no real content.
70 *
71 * Removes the Utilities tab entirely when the only available sections
72 * are upsell placeholders (i.e. Pro is active but no utility addons
73 * are installed).
74 *
75 * @param array $tabs Registered settings tabs.
76 * @return array
77 */
78 public static function reorder_settings_tabs( $tabs ) {
79
80 // Hide Utilities tab if it has no real (non-upsell) sections.
81 if ( isset( $tabs['utilities'] ) ) {
82 $utilities_page = null;
83
84 foreach ( self::$settings as $page ) {
85 if ( isset( $page->id ) && 'utilities' === $page->id ) {
86 $utilities_page = $page;
87 break;
88 }
89 }
90
91 if ( $utilities_page && method_exists( $utilities_page, 'has_real_sections' ) ) {
92 if ( ! $utilities_page->has_real_sections() ) {
93 unset( $tabs['utilities'] );
94 }
95 }
96 }
97
98 // Keep Advanced and License always at the end.
99 $advanced = null;
100 $license = null;
101
102 if ( isset( $tabs['advanced'] ) ) {
103 $advanced = $tabs['advanced'];
104 unset( $tabs['advanced'] );
105 }
106
107 if ( isset( $tabs['license'] ) ) {
108 $license = $tabs['license'];
109 unset( $tabs['license'] );
110 }
111
112 if ( null !== $advanced ) {
113 $tabs['advanced'] = $advanced;
114 }
115
116 if ( null !== $license ) {
117 $tabs['license'] = $license;
118 }
119
120 return $tabs;
121 }
122
123 /**
124 * Save the settings.
125 */
126 public static function save() {
127 global $current_tab;
128
129 check_admin_referer( 'everest-forms-settings' );
130
131 // Trigger actions.
132 do_action( 'everest_forms_settings_save_' . $current_tab );
133 do_action( 'everest_forms_update_options_' . $current_tab );
134 do_action( 'everest_forms_update_options' );
135 $flag = apply_filters( 'show_everest_forms_setting_message', true );
136 if ( $flag ) {
137 self::add_message( esc_html__( 'Your settings have been saved.', 'everest-forms' ) );
138 }
139
140 // Clear any unwanted data and flush rules.
141 update_option( 'everest_forms_queue_flush_rewrite_rules', 'yes' );
142
143 do_action( 'everest_forms_settings_saved' );
144 }
145
146 /**
147 * Add a message.
148 *
149 * @param string $text Message.
150 */
151 public static function add_message( $text ) {
152 self::$messages[] = $text;
153 }
154
155 /**
156 * Add an error.
157 *
158 * @param string $text Message.
159 */
160 public static function add_error( $text ) {
161 self::$errors[] = $text;
162 }
163
164 /**
165 * Output messages + errors.
166 */
167 public static function show_messages() {
168 if ( count( self::$errors ) > 0 ) {
169 foreach ( self::$errors as $error ) {
170 echo '<div id="message" class="error inline"><p><strong>' . wp_kses_post( $error ) . '</strong></p></div>';
171 }
172 } elseif ( count( self::$messages ) > 0 ) {
173 foreach ( self::$messages as $message ) {
174 echo '<div id="message" class="updated inline"><p><strong>' . esc_html( $message ) . '</strong></p></div>';
175 }
176 }
177 }
178
179 /**
180 * Settings page.
181 *
182 * Handles the display of the main everest-forms settings page in admin.
183 */
184 public static function output() {
185 global $current_section, $current_tab;
186
187 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
188
189 do_action( 'everest_forms_settings_start' );
190
191 wp_enqueue_script( 'everest_forms_settings', evf()->plugin_url() . '/assets/js/admin/settings' . $suffix . '.js', array( 'jquery', 'jquery-confirm', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'selectWoo' ), evf()->version, true );
192
193 wp_localize_script(
194 'everest_forms_settings',
195 'everest_forms_settings_params',
196 array(
197 'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'everest-forms' ),
198 )
199 );
200
201 // Get tabs for the settings page.
202 $tabs = apply_filters( 'everest_forms_settings_tabs_array', array() );
203
204 include __DIR__ . '/views/html-admin-settings.php';
205 }
206
207 /**
208 * Get a setting from the settings API.
209 *
210 * @param string $option_name Option name.
211 * @param mixed $default Default value.
212 * @return mixed
213 */
214 public static function get_option( $option_name, $default = '' ) {
215 if ( ! $option_name ) {
216 return $default;
217 }
218
219 // Array value.
220 if ( strstr( $option_name, '[' ) ) {
221
222 parse_str( $option_name, $option_array );
223
224 // Option name is first key.
225 $option_name = current( array_keys( $option_array ) );
226
227 // Get value.
228 $option_values = get_option( $option_name, '' );
229
230 $key = key( $option_array[ $option_name ] );
231
232 if ( isset( $option_values[ $key ] ) ) {
233 $option_value = $option_values[ $key ];
234 } else {
235 $option_value = null;
236 }
237 } else {
238 // Single value.
239 $option_value = get_option( $option_name, null );
240 }
241
242 if ( is_array( $option_value ) ) {
243 $option_value = array_map( 'stripslashes', $option_value );
244 } elseif ( ! is_null( $option_value ) ) {
245 $option_value = stripslashes( $option_value );
246 }
247
248 return ( null === $option_value ) ? $default : $option_value;
249 }
250
251 /**
252 * Output admin fields.
253 *
254 * Loops though the everest-forms options array and outputs each field.
255 *
256 * @param array[] $options Opens array to output.
257 */
258 public static function output_fields( $options ) {
259 $settings = '';
260 foreach ( $options as $value ) {
261 if ( ! isset( $value['type'] ) ) {
262 continue;
263 }
264 if ( ! isset( $value['id'] ) ) {
265 $value['id'] = '';
266 }
267 if ( ! isset( $value['title'] ) ) {
268 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
269 }
270 if ( ! isset( $value['class'] ) ) {
271 $value['class'] = '';
272 }
273 if ( ! isset( $value['css'] ) ) {
274 $value['css'] = '';
275 }
276 if ( ! isset( $value['default'] ) ) {
277 $value['default'] = '';
278 }
279 if ( ! isset( $value['desc'] ) ) {
280 $value['desc'] = '';
281 }
282 if ( ! isset( $value['desc_tip'] ) ) {
283 $value['desc_tip'] = false;
284 }
285 if ( ! isset( $value['placeholder'] ) ) {
286 $value['placeholder'] = '';
287 }
288 if ( ! isset( $value['suffix'] ) ) {
289 $value['suffix'] = '';
290 }
291 if ( ! isset( $value['value'] ) ) {
292 $value['value'] = self::get_option( $value['id'], $value['default'] );
293 }
294
295 // Custom attribute handling.
296 $custom_attributes = array();
297
298 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
299 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
300 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
301 }
302 }
303
304 // Description handling.
305 $field_description = self::get_field_description( $value );
306 $description = $field_description['description'];
307 $tooltip_html = $field_description['tooltip_html'];
308 // Switch based on type.
309 switch ( $value['type'] ) {
310
311 // Section Titles.
312 case 'title':
313 if ( ! empty( $value['title'] ) ) {
314 $tabs = apply_filters( 'everest_forms_settings_tabs_array', array() );
315 $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
316 $tabs_array = array();
317 if ( isset( $tabs[ $current_tab ] ) ) {
318 $tabs_array[ $current_tab ] = isset( $tabs_array[ $current_tab ] ) ? $tabs_array[ $current_tab ] : array();
319 }
320
321 $class_for_title = isset( $value['id'] ) && ! empty( $value['id'] ) ? 'everest-forms-settings-title_' . $value['id'] : '';
322
323 echo '<div class="everest-forms-options-header ' . esc_attr( $class_for_title ) . '">
324 <div class="everest-forms-options-header--top">';
325
326 if ( isset( $value['image_name'] ) && ! empty( $value['image_name'] ) ) {
327 // Icon for Settings tab with different icon.
328 // echo '<span class="evf-forms-options-header-header--top-icon">' . evf_file_get_contents( '/assets/images/settings-icons/' . $value['image_name'] . '.svg' ) . '</span>';
329 } else {
330 foreach ( $tabs_array as $icon_key => $icon_value ) {
331 echo '<span class="evf-forms-options-header-header--top-icon">' . evf_file_get_contents( '/assets/images/settings-icons/' . $icon_key . '.svg' ) . '</span>'; //phpcs:ignore
332 }
333 }
334
335 echo '<h3>' . esc_html( $value['title'] ) . '</h3>
336 </div>
337 </div>';
338
339 }
340 if ( ! empty( $value['desc'] ) ) {
341 echo wp_kses_post( wpautop( wptexturize( $value['desc'] ) ) );
342 }
343 echo '<div class="everest-forms-card">' . "\n\n";
344 if ( ! empty( $value['id'] ) ) {
345 do_action( 'everest_forms_settings_' . sanitize_title( $value['id'] ) );
346 }
347 break;
348
349 // Section Ends.
350 case 'sectionend':
351 if ( ! empty( $value['id'] ) ) {
352 do_action( 'everest_forms_settings_' . sanitize_title( $value['id'] ) . '_end' );
353 }
354 echo '</div>';
355 if ( ! empty( $value['id'] ) ) {
356 do_action( 'everest_forms_settings_' . sanitize_title( $value['id'] ) . '_after' );
357 }
358 break;
359
360 // Standard text inputs and subtypes like 'number'.
361 case 'text':
362 case 'password':
363 case 'datetime':
364 case 'datetime-local':
365 case 'date':
366 case 'date-time':
367 case 'month':
368 case 'time':
369 case 'week':
370 case 'number':
371 case 'email':
372 case 'url':
373 case 'tel':
374 $option_value = $value['value'];
375 $visibility_class = array();
376
377 if ( isset( $value['is_visible'] ) ) {
378 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
379 }
380
381 if ( empty( $option_value ) ) {
382 $option_value = $value['default'];
383 }
384
385 ?><div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
386 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
387 <?php echo wp_kses_post( $tooltip_html ); ?></label>
388 <div
389 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
390 <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
391 type="<?php echo esc_attr( $value['type'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
392 value="<?php echo esc_attr( $option_value ); ?>" class="<?php echo esc_attr( $value['class'] ); ?>"
393 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
394 <?php
395 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
396 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
397 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
398 }
399 }
400 ?>
401 /><?php echo esc_html( $value['suffix'] ); ?> <?php echo wp_kses_post( $description ); ?>
402 </div>
403 </div>
404 <?php
405 break;
406 case 'image':
407 $option_value = $value['value'];
408 if ( empty( $option_value ) ) {
409 $option_value = $value['default'];
410 }
411 $visibility_class = array();
412 if ( isset( $value['is_visible'] ) ) {
413 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
414 }
415
416 $upload_text = __( 'Upload Logo', 'everest-forms' );
417 $alt_text = __( 'Header Logo', 'everest-forms' );
418 if ( 'everest_forms_pdf_background_image' === $value['id'] ) {
419 $upload_text = __( 'Upload Image', 'everest-forms' );
420 $alt_text = __( 'Background Image', 'everest-forms' );
421 }
422
423 ?>
424 <div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
425 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
426 <?php echo wp_kses_post( $tooltip_html ); ?></label>
427 <div
428 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
429 <div class="evf-image-container " <?php echo empty( $option_value ) ? 'style=display:none' : ''; ?>>
430 <i class="evf-icon evf-icon-delete"></i>
431 <img src="<?php echo esc_attr( $option_value ); ?>" alt="<?php echo esc_attr( $alt_text ); ?>"
432 class="evf-button-form-image-delete <?php echo empty( $option_value ) ? 'everest-forms-hidden' : ''; ?>"
433 height="100" width="auto">
434 </div>
435 <button type="button" class="evf-button-for-image-upload evf-button button-secondary"
436 <?php echo empty( $option_value ) ? '' : 'style="display:none"'; ?>><?php echo esc_html( $upload_text ); ?></button>
437 <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
438 value="<?php echo esc_attr( $option_value ); ?>" type="hidden">
439 </div>
440 </div>
441 <?php
442 // Adding scripts.
443 wp_enqueue_script( 'jquery' );
444 wp_enqueue_media();
445 wp_enqueue_script( 'evf-file-uploader' );
446 break;
447
448 // Color picker.
449 case 'color':
450 $option_value = $value['value'];
451
452 ?>
453 <div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
454 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
455 <?php echo wp_kses_post( $tooltip_html ); ?></label>
456 <div class="everest-forms-global-settings--field ">
457 <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="text"
458 dir="ltr" style="<?php echo esc_attr( $value['css'] ); ?>" value="<?php echo esc_attr( $option_value ); ?>"
459 class="<?php echo esc_attr( $value['class'] ); ?>evf-colorpicker"
460 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
461 <?php
462 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
463 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
464 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
465 }
466 }
467 ?>
468 />&lrm; <?php echo wp_kses_post( $description ); ?>
469 <div id="colorPickerDiv_<?php echo esc_attr( $value['id'] ); ?>" class="colorpickdiv"
470 style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>
471 </div>
472 </div>
473 <?php
474 break;
475
476 // Textarea.
477 case 'textarea':
478 $option_value = $value['value'];
479
480 ?>
481 <div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
482 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
483 <?php echo wp_kses_post( $tooltip_html ); ?></label>
484 <div
485 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
486 <?php echo wp_kses_post( $description ); ?>
487
488 <textarea name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
489 style="<?php echo esc_attr( $value['css'] ); ?>" class="<?php echo esc_attr( $value['class'] ); ?>"
490 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
491 <?php
492 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
493 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
494 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
495 }
496 }
497 ?>
498 ><?php echo esc_textarea( $option_value ); ?></textarea>
499 </div>
500 </div>
501 <?php
502 break;
503
504 // TinyMCE.
505 case 'tinymce':
506 $option_value = $value['value'];
507 ?>
508 <div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
509 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
510 <div
511 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
512 <?php
513 $arguments = array(
514 'media_buttons' => false,
515 'tinymce' => false,
516 'textarea_rows' => get_option( 'default_post_edit_rows', 10 ),
517 'editor_class' => 'everest_forms_tinymce_class',
518 'textarea_content' => true,
519 'teeny' => true,
520 );
521 $arguments['textarea_name'] = $value['id'];
522 $arguments['teeny'] = true;
523 $id = $value['id'];
524 $content = html_entity_decode( $option_value );
525 ob_start();
526 wp_editor( $content, $id, $arguments );
527 $output = ob_get_clean();
528 echo wp_kses_post( $output );
529 echo '<em>' . wp_kses_post( $description ) . '</em>';
530 ?>
531 </div>
532 </div>
533
534 <?php
535 break;
536
537 // Select boxes.
538 case 'select':
539 case 'multiselect':
540 $option_value = $value['value'];
541
542 ?>
543 <div class="everest-forms-global-settings">
544 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
545 <?php echo wp_kses_post( $tooltip_html ); ?></label>
546 <div
547 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
548 <select
549 name="<?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
550 id="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
551 class="<?php echo esc_attr( $value['class'] ); ?>"
552 <?php
553 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
554 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
555 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
556 }
557 }
558 ?>
559 <?php echo 'multiselect' === $value['type'] ? 'multiple="multiple"' : ''; ?>>
560 <?php
561 foreach ( $value['options'] as $key => $val ) {
562 ?>
563 <option value="<?php echo esc_attr( $key ); ?>"
564 <?php
565
566 if ( is_array( $option_value ) ) {
567 selected( in_array( (string) $key, $option_value, true ), true );
568 } else {
569 selected( $option_value, (string) $key );
570 }
571
572 ?>
573 >
574 <?php echo esc_html( $val ); ?></option>
575 <?php
576 }
577 ?>
578 </select> <?php echo wp_kses_post( $description ); ?>
579 </div>
580 </div>
581 <?php
582 break;
583
584 // Radio inputs.
585 case 'radio':
586 $option_value = $value['value'];
587
588 ?>
589 <div class="everest-forms-global-settings">
590 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
591 <?php echo wp_kses_post( $tooltip_html ); ?></label>
592 <div
593 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
594 <fieldset>
595 <?php echo wp_kses_post( $description ); ?>
596 <ul class="<?php echo esc_attr( $value['class'] ); ?>">
597 <?php
598 foreach ( $value['options'] as $key => $val ) {
599 ?>
600 <li>
601 <label><input name="<?php echo esc_attr( $value['id'] ); ?>"
602 id="<?php echo esc_attr( $value['id'] ); ?>" value="<?php echo esc_attr( $key ); ?>"
603 type="radio" style="<?php echo esc_attr( $value['css'] ); ?>"
604 class="<?php echo esc_attr( $value['class'] ); ?>"
605 <?php
606 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
607 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
608 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
609 }
610 }
611 ?>
612 <?php checked( $key, $option_value ); ?> /> <?php echo esc_html( $val ); ?></label>
613 </li>
614 <?php
615 }
616 ?>
617 </ul>
618 </fieldset>
619 </div>
620 </div>
621 <?php
622 break;
623
624 // Toggle input.
625 case 'toggle':
626 $option_value = $value['value'];
627
628 if ( empty( $option_value ) ) {
629 $option_value = $value['default'];
630 }
631 ?>
632 <div class="everest-forms-global-settings">
633 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
634 <div class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?> ">
635 <?php echo wp_kses_post( $description ); ?>
636 <div class="evf-toggle-section">
637 <span class="everest-forms-toggle-form">
638 <input type="checkbox" name="<?php echo esc_attr( $value['id'] ); ?>"
639 id="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>"
640 class="<?php echo esc_attr( $value['class'] ); ?>" value="yes"
641 <?php checked( 'yes', $option_value, true ); ?>>
642 <span class="slider round"></span>
643 </span>
644 </div>
645 </div>
646 </div>
647
648 <?php
649 break;
650
651 // Radio image inputs.
652 case 'radio-image':
653 $option_value = $value['value'];
654 if ( isset( $value['id'] ) && 'everest_forms_recaptcha_type' === $value['id'] ) {
655 $class = 'everest-forms-recaptcha-settings';
656 } else {
657 $class = '';
658 }
659
660 ?>
661 <div class="everest-forms-global-settings">
662 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
663 <div class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?> <?php echo esc_attr( $class ); ?>">
664 <fieldset>
665 <ul>
666 <?php
667 foreach ( $value['options'] as $key => $val ) {
668 ?>
669 <li>
670 <input
671 name="<?php echo esc_attr( $value['id'] ); ?>"
672 value="<?php echo esc_attr( $key ); ?>"
673 type="radio"
674 style="<?php echo esc_attr( $value['css'] ); ?>"
675 class="<?php echo esc_attr( $value['class'] ); ?>"
676 id="evf-global-settings-<?php echo esc_attr( str_replace( ' ', '-', strtolower( $val['name'] ) ) ); ?>"
677 <?php
678 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
679 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
680 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
681 }
682 }
683 ?>
684 <?php checked( $key, $option_value ); ?>
685 />
686 <label for="evf-global-settings-<?php echo esc_attr( str_replace( ' ', '-', strtolower( $val['name'] ) ) ); ?>">
687 <img src="<?php echo esc_html( $val['image'] ); ?>">
688 <?php echo esc_html( $val['name'] ); ?>
689 </label>
690 </li>
691 <?php
692 }
693 ?>
694 </ul>
695 <?php echo wp_kses_post( $description ); ?>
696 </fieldset>
697 </div>
698 </div>
699 <?php
700 break;
701
702 // Checkbox input.
703 case 'checkbox':
704 $option_value = $value['value'];
705 $visibility_class = array();
706
707 if ( ! isset( $value['hide_if_checked'] ) ) {
708 $value['hide_if_checked'] = false;
709 }
710 if ( ! isset( $value['show_if_checked'] ) ) {
711 $value['show_if_checked'] = false;
712 }
713 if ( 'yes' === $value['hide_if_checked'] || 'yes' === $value['show_if_checked'] ) {
714 $visibility_class[] = 'hidden_option';
715 }
716 if ( 'option' === $value['hide_if_checked'] ) {
717 $visibility_class[] = 'hide_options_if_checked';
718 }
719 if ( 'option' === $value['show_if_checked'] ) {
720 $visibility_class[] = 'show_options_if_checked';
721 }
722 if ( isset( $value['is_visible'] ) ) {
723 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
724 }
725
726 if ( ! isset( $value['checkboxgroup'] ) || 'start' === $value['checkboxgroup'] ) {
727 ?>
728 <div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
729 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
730 <?php echo wp_kses_post( $tooltip_html ); ?></label>
731 <div class="everest-forms-global-settings--field">
732 <fieldset>
733 <?php
734 } else {
735 ?>
736 <fieldset class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
737 <?php
738 }
739
740 if ( ! empty( $value['title'] ) ) {
741 ?>
742 <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ); ?></span></legend>
743 <?php
744 }
745
746 ?>
747 <label for="<?php echo esc_attr( $value['id'] ); ?>">
748 <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>"
749 type="checkbox"
750 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>" value="1"
751 <?php checked( $option_value, 'yes' ); ?>
752 <?php
753 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
754 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
755 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
756 }
757 }
758 ?>
759 />
760 <?php echo wp_kses_post( $description ); ?>
761 </label> <?php echo wp_kses_post( $tooltip_html ); ?>
762 <?php
763
764 if ( ! isset( $value['checkboxgroup'] ) || 'end' === $value['checkboxgroup'] ) {
765 ?>
766 </fieldset>
767 </div>
768 </div>
769 <?php
770 } else {
771 ?>
772 </fieldset>
773 <?php
774 }
775 break;
776
777 // Single page selects.
778 case 'single_select_page':
779 $args = array(
780 'name' => $value['id'],
781 'id' => $value['id'],
782 'sort_column' => 'menu_order',
783 'sort_order' => 'ASC',
784 'show_option_none' => ' ',
785 'class' => $value['class'],
786 'echo' => false,
787 'selected' => absint( $value['value'] ),
788 'post_status' => 'publish,private,draft',
789 );
790
791 if ( isset( $value['args'] ) ) {
792 $args = wp_parse_args( $value['args'], $args );
793 }
794
795 ?>
796 <div class="everest-forms-global-settings single_select_page"">
797 <label><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
798 <div class=" everest-forms-global-settings--field
799 forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
800 <?php echo wp_kses_post( str_replace( ' id=', " data-placeholder='" . esc_attr__( 'Select a page&hellip;', 'everest-forms' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ) ); ?>
801 <?php echo wp_kses_post( $description ); ?>
802 </div>
803 </div>
804 <?php
805 break;
806
807 // Days/months/years selector.
808 case 'relative_date_selector':
809 $periods = array(
810 'days' => __( 'Day(s)', 'everest-forms' ),
811 'weeks' => __( 'Week(s)', 'everest-forms' ),
812 'months' => __( 'Month(s)', 'everest-forms' ),
813 'years' => __( 'Year(s)', 'everest-forms' ),
814 );
815 $option_value = evf_parse_relative_date_option( $value['value'] );
816 ?>
817 <div class="everest-forms-global-settings">
818 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
819 <?php echo wp_kses_post( $tooltip_html ); ?></label>
820 <div
821 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
822 <input name="<?php echo esc_attr( $value['id'] ); ?>[number]" id="<?php echo esc_attr( $value['id'] ); ?>"
823 type="number" style="width: 80px;" value="<?php echo esc_attr( $option_value['number'] ); ?>"
824 class="<?php echo esc_attr( $value['class'] ); ?>"
825 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>" step="1" min="1"
826 <?php
827 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
828 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
829 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
830 }
831 }
832 ?>
833 />&nbsp;
834 <select name="<?php echo esc_attr( $value['id'] ); ?>[unit]" style="width: auto;">
835 <?php
836 foreach ( $periods as $value => $label ) {
837 echo '<option value="' . esc_attr( $value ) . '"' . selected( $option_value['unit'], $value, false ) . '>' . esc_html( $label ) . '</option>';
838 }
839 ?>
840 </select> <?php echo ( $description ) ? wp_kses_post( $description ) : ''; ?>
841 </div>
842 </div>
843 <?php
844 break;
845
846 // For anchor tag.
847 case 'link':
848 ?>
849 <div class="everest-forms-global-settings">
850 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
851 <?php echo wp_kses_post( $tooltip_html ); ?></label>
852 <div
853 class="everest-forms-global-settings--field forminp-<?php echo isset( $value['type'] ) ? esc_attr( sanitize_title( $value['type'] ) ) : ''; ?>">
854 <?php
855 if ( isset( $value['buttons'] ) && is_array( $value['buttons'] ) ) {
856 foreach ( $value['buttons'] as $button ) {
857 ?>
858 <a href="<?php echo isset( $button['href'] ) ? esc_url( $button['href'] ) : ''; ?>"
859 class="button <?php echo isset( $button['class'] ) ? esc_attr( $button['class'] ) : ''; ?>"
860 style="<?php echo isset( $value['css'] ) ? esc_attr( $value['css'] ) : ''; ?>"
861 <?php
862 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
863 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
864 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
865 }
866 }
867 ?>
868 >
869 <?php echo isset( $button['title'] ) ? esc_html( $button['title'] ) : ''; ?>
870 </a>
871 <?php
872 }
873 }
874 ?>
875 <?php echo isset( $value['suffix'] ) ? esc_html( $value['suffix'] ) : ''; ?>
876 <?php echo isset( $description ) ? wp_kses_post( $description ) : ''; ?>
877 </div>
878 </div>
879 <?php
880 break;
881
882 case 'input_test_button':
883 $option_value = $value['value'];
884 $visibility_class = array();
885
886 if ( isset( $value['is_visible'] ) ) {
887 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
888 }
889
890 if ( empty( $option_value ) ) {
891 $option_value = $value['default'];
892 }
893
894 ?>
895 <div class="everest-forms-global-settings <?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
896 <label for="<?php echo esc_attr( $value['input_id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
897 <?php echo wp_kses_post( $tooltip_html ); ?></label>
898 <div
899 class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
900 <input name="<?php echo isset( $value['input_id'] ) ? esc_attr( $value['input_id'] ) : ''; ?>"
901 id="<?php echo isset( $value['input_id'] ) ? esc_attr( $value['input_id'] ) : ''; ?>"
902 type="<?php echo isset( $value['input_type'] ) ? esc_attr( $value['input_type'] ) : ''; ?>"
903 style="<?php echo isset( $value['input_css'] ) ? esc_attr( $value['input_css'] ) : ''; ?>"
904 value="<?php echo isset( $option_value ) ? esc_attr( $option_value ) : ''; ?>"
905 class="<?php echo isset( $value['class'] ) ? esc_attr( $value['class'] ) : ''; ?>"
906 placeholder="<?php echo isset( $value['placeholder'] ) ? esc_attr( $value['placeholder'] ) : ''; ?>"
907 <?php
908 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
909 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
910 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
911 }
912 }
913 ?>
914 /><?php echo isset( $value['suffix'] ) ? esc_html( $value['suffix'] ) : ''; ?>
915 <?php echo isset( $description ) ? wp_kses_post( $description ) : ''; ?>
916 <?php
917 if ( isset( $value['buttons'] ) && is_array( $value['buttons'] ) ) {
918 foreach ( $value['buttons'] as $button ) {
919 ?>
920 <a href="<?php echo esc_url( $button['href'] ); ?>" class="button <?php echo esc_attr( $button['class'] ); ?>"
921 style="<?php echo isset( $value['button_css'] ) ? esc_attr( $value['button_css'] ) : ''; ?>"
922 <?php
923 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
924 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
925 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
926 }
927 }
928 ?>
929 >
930 <?php echo esc_html( $button['title'] ); ?>
931 </a>
932 <?php
933 }
934 }
935 ?>
936 <?php echo esc_html( $value['suffix'] ); ?> <?php echo wp_kses_post( $description ); ?>
937 </div>
938 </div>
939 <?php
940 break;
941
942 case 'restapi_key':
943 $key = $value['value'];
944 $key = $value['value'];
945 $restapi_enabled = get_option( 'everest_forms_enable_restapi', 'no' );
946 $restapi_wrapper_style = ( 'yes' === $restapi_enabled ) ? '' : 'display:none;';
947
948 ?>
949 <div class="everest-forms-global-settings evf-restapi-key-wrapper" style="<?php echo esc_attr( $restapi_wrapper_style ); ?>">
950 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
951 <?php echo wp_kses_post( $tooltip_html ); ?></label>
952 <div class="everest-forms-global-settings--field forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>"
953 style="display:flex; gap:2px">
954 <?php echo wp_kses_post( $description ); ?>
955 <input type="text" style="" id="<?php echo esc_attr( $value['id'] ); ?>"
956 name="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?> "
957 class="<?php echo esc_attr( $value['class'] ); ?> help_tip tooltipstered"
958 value="<?php echo esc_attr( $key ); ?>" data-tip="Copy ApiKey" data-copied="Copied!" readonly />
959 <div>
960 <?php
961 $unique_id = isset( $value['id'] ) ? $value['id'] : '';
962 if ( '' === $key ) {
963 echo '<button type="button" id="' . $unique_id . '" data-id="' . $unique_id . '" class="everest-forms-btn everest-forms-btn-primary everest-forms-generate-api-key">generate</button>';
964 } else {
965 echo '<button type="button" id="' . $unique_id . '" data-id="' . $unique_id . '" class="everest-forms-btn everest-forms-btn-primary everest-forms-generate-api-key ' . $unique_id . '">regenerate</button>';
966 }
967 ?>
968 </div>
969 </div>
970 </div>
971 <?php
972 break;
973
974 case 'display_div':
975 ?>
976 <div class="everest-forms-global-settings">
977 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?>
978 <?php echo wp_kses_post( $tooltip_html ); ?></label>
979 <div
980 class="everest-forms-global-settings--field forminp-<?php echo isset( $value['type'] ) ? esc_attr( sanitize_title( $value['type'] ) ) : ''; ?>">
981 <?php
982 echo ! empty( $value['value'] ) ? esc_html( $value['value'] ) : '';
983 ?>
984 </div>
985 </div>
986 <?php
987 break;
988
989 case 'accordion':
990 if ( ! isset( $value['items'] ) || ! is_array( $value['items'] ) ) {
991 break;
992 }
993 ?>
994 <div class="everest-forms-accordion-wrapper">
995 <?php foreach ( $value['items'] as $index => $item ) : ?>
996 <?php
997 $is_connected = false;
998 if ( isset( $item['is_enabled'] ) ) {
999 $is_connected = $item['is_enabled'];
1000 } elseif ( isset( $item['connection_check'] ) ) {
1001 $connection_check = $item['connection_check'];
1002
1003 // Handle grouped checks (test OR live credentials).
1004 if ( isset( $connection_check['groups'] ) && is_array( $connection_check['groups'] ) ) {
1005 $mode = isset( $connection_check['mode'] ) ? $connection_check['mode'] : 'any_group';
1006 $is_connected = false;
1007
1008 foreach ( $connection_check['groups'] as $group_name => $group_fields ) {
1009 $group_complete = true;
1010 foreach ( $group_fields as $field_id ) {
1011 $field_value = get_option( $field_id, '' );
1012 if ( empty( $field_value ) ) {
1013 $group_complete = false;
1014 break;
1015 }
1016 }
1017
1018 if ( $group_complete ) {
1019 $is_connected = true;
1020 if ( 'any_group' === $mode ) {
1021 break;
1022 }
1023 }
1024 }
1025 } elseif ( is_array( $connection_check ) ) {
1026 $is_connected = true;
1027 foreach ( $connection_check as $field_id ) {
1028 $field_value = get_option( $field_id, '' );
1029 if ( empty( $field_value ) ) {
1030 $is_connected = false;
1031 break;
1032 }
1033 }
1034 }
1035 }
1036
1037 $item_classes = array( 'everest-forms-accordion-item' );
1038 if ( $is_connected ) {
1039 $item_classes[] = 'is-connected';
1040 }
1041 ?>
1042 <div class="<?php echo esc_attr( implode( ' ', $item_classes ) ); ?>" data-accordion-index="<?php echo esc_attr( $index ); ?>">
1043
1044 <div class="everest-forms-accordion-header">
1045 <div class="everest-forms-accordion-status">
1046 <span class="toggle-switch-outer <?php echo $is_connected ? 'connected' : 'disconnected'; ?>"></span>
1047 </div>
1048
1049 <?php if ( isset( $item['icon'] ) ) : ?>
1050 <span class="everest-forms-accordion-icon">
1051 <img src="<?php echo esc_url( $item['icon'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>">
1052 </span>
1053 <?php endif; ?>
1054
1055 <h3 class="everest-forms-accordion-title">
1056 <?php echo esc_html( $item['title'] ); ?>
1057 </h3>
1058
1059 <span class="everest-forms-accordion-toggle">
1060 <svg width="20" height="20" viewBox="0 0 20 20" fill="none">
1061 <path d="M5 7.5L10 12.5L15 7.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
1062 </svg>
1063 </span>
1064 </div>
1065 <div class="everest-forms-accordion-content">
1066 <div class="everest-forms-accordion-content-inner">
1067 <?php
1068 if ( isset( $item['fields'] ) && is_array( $item['fields'] ) ) {
1069 self::output_fields( $item['fields'] );
1070 }
1071 ?>
1072 </div>
1073 </div>
1074 </div>
1075 <?php endforeach; ?>
1076 </div>
1077 <?php
1078 break;
1079
1080 default:
1081 do_action( 'everest_forms_admin_field_' . $value['type'], $value );
1082 break;
1083 }
1084 }
1085 }
1086
1087 /**
1088 * Helper function to get the formatted description and tip HTML for a
1089 * given form field. Plugins can call this when implementing their own custom
1090 * settings types.
1091 *
1092 * @param array $value The form field value array.
1093 * @return array The description and tip as a 2 element array.
1094 */
1095 public static function get_field_description( $value ) {
1096 $description = '';
1097 $tooltip_html = '';
1098
1099 if ( true === $value['desc_tip'] ) {
1100 $tooltip_html = $value['desc'];
1101 } elseif ( ! empty( $value['desc_tip'] ) ) {
1102 $description = $value['desc'];
1103 $tooltip_html = $value['desc_tip'];
1104 } elseif ( ! empty( $value['desc'] ) ) {
1105 $description = $value['desc'];
1106 }
1107
1108 if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ), true ) ) {
1109 $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
1110 } elseif ( $description && in_array( $value['type'], array( 'checkbox' ), true ) ) {
1111 $description = wp_kses_post( $description );
1112 } elseif ( $description ) {
1113 $description = '<p class="description">' . wp_kses_post( $description ) . '</p>';
1114 }
1115
1116 if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ), true ) ) {
1117 $tooltip_html = '<p class="description">' . $tooltip_html . '</p>';
1118 } elseif ( $tooltip_html ) {
1119 $tooltip_html = evf_help_tip( $tooltip_html );
1120 }
1121
1122 return array(
1123 'description' => $description,
1124 'tooltip_html' => $tooltip_html,
1125 );
1126 }
1127
1128 /**
1129 * Save admin fields.
1130 *
1131 * Loops though the everest-forms options array and outputs each field.
1132 *
1133 * @param array $options Options array to output.
1134 * @param array $data Optional. Data to use for saving. Defaults to $_POST.
1135 * @return bool
1136 */
1137 public static function save_fields( $options, $data = null ) {
1138 if ( is_null( $data ) ) {
1139 $data = $_POST; // phpcs:ignore WordPress.Security.NonceVerification
1140 }
1141 if ( empty( $data ) ) {
1142 return false;
1143 }
1144
1145 $update_options = array();
1146 $autoload_options = array();
1147
1148 foreach ( $options as $option ) {
1149
1150 if ( isset( $option['type'] ) && 'accordion' === $option['type'] ) {
1151 if ( isset( $option['items'] ) && is_array( $option['items'] ) ) {
1152 foreach ( $option['items'] as $item ) {
1153 if ( isset( $item['fields'] ) && is_array( $item['fields'] ) ) {
1154 self::save_fields( $item['fields'], $data );
1155 }
1156 }
1157 }
1158 continue;
1159 }
1160
1161 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) || ( isset( $option['is_option'] ) && false === $option['is_option'] ) ) {
1162 continue;
1163 }
1164
1165 // Get posted value.
1166 if ( strstr( $option['id'], '[' ) ) {
1167 parse_str( $option['id'], $option_name_array );
1168 $option_name = current( array_keys( $option_name_array ) );
1169 $setting_name = key( $option_name_array[ $option_name ] );
1170 $raw_value = isset( $data[ $option_name ][ $setting_name ] ) ? wp_unslash( $data[ $option_name ][ $setting_name ] ) : null;
1171 } else {
1172 $option_name = $option['id'];
1173 $setting_name = '';
1174 $raw_value = isset( $data[ $option['id'] ] ) ? wp_unslash( $data[ $option['id'] ] ) : null;
1175 }
1176
1177 // Format the value based on option type.
1178 switch ( $option['type'] ) {
1179 case 'checkbox':
1180 $value = '1' === $raw_value || 'yes' === $raw_value ? 'yes' : 'no';
1181 break;
1182 case 'toggle':
1183 $value = '1' === $raw_value || 'yes' === $raw_value ? 'yes' : 'no';
1184 break;
1185 case 'textarea':
1186 case 'tinymce':
1187 $value = wp_kses_post( trim( $raw_value ) );
1188 break;
1189 case 'select':
1190 $allowed_values = empty( $option['options'] ) ? array() : array_map( 'strval', array_keys( $option['options'] ) );
1191 if ( empty( $option['default'] ) && empty( $allowed_values ) ) {
1192 $value = null;
1193 break;
1194 }
1195 $default = ( empty( $option['default'] ) ? $allowed_values[0] : $option['default'] );
1196 $value = in_array( $raw_value, $allowed_values, true ) ? $raw_value : $default;
1197 break;
1198 default:
1199 if ( is_string( $raw_value ) ) {
1200 $decoded_value = html_entity_decode( html_entity_decode( $raw_value ) );
1201 $value = wp_kses_post( $decoded_value );
1202 } else {
1203 $value = evf_clean( $raw_value );
1204 }
1205 break;
1206 }
1207
1208 /**
1209 * Sanitize the value of an option.
1210 *
1211 * @since 1.0.0
1212 */
1213 $value = apply_filters( 'everest_forms_admin_settings_sanitize_option', $value, $option, $raw_value );
1214
1215 /**
1216 * Sanitize the value of an option by option name.
1217 *
1218 * @since 1.0.0
1219 */
1220 $value = apply_filters( "everest_forms_admin_settings_sanitize_option_$option_name", $value, $option, $raw_value );
1221
1222 if ( is_null( $value ) ) {
1223 continue;
1224 }
1225
1226 // Check if option is an array and handle that differently to single values.
1227 if ( $option_name && $setting_name ) {
1228 if ( ! isset( $update_options[ $option_name ] ) ) {
1229 $update_options[ $option_name ] = get_option( $option_name, array() );
1230 }
1231 if ( ! is_array( $update_options[ $option_name ] ) ) {
1232 $update_options[ $option_name ] = array();
1233 }
1234 $update_options[ $option_name ][ $setting_name ] = $value;
1235 } else {
1236 $update_options[ $option_name ] = $value;
1237 }
1238
1239 $autoload_options[ $option_name ] = isset( $option['autoload'] ) ? (bool) $option['autoload'] : true;
1240
1241 /**
1242 * Fire an action before saved.
1243 *
1244 * @deprecated 1.2.0 - doesn't allow manipulation of values!
1245 */
1246 do_action( 'everest_forms_update_option', $option );
1247 }
1248
1249 // Save all options in our array.
1250 foreach ( $update_options as $name => $value ) {
1251 update_option( $name, $value, $autoload_options[ $name ] ? 'yes' : 'no' );
1252 }
1253
1254 return true;
1255 }
1256 }
1257
1258 endif;
1259