PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.3
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 years ago plugin-updates 8 years ago settings 2 years ago views 2 years ago class-evf-admin-addons.php 4 years ago class-evf-admin-assets.php 2 years ago class-evf-admin-builder.php 7 years ago class-evf-admin-deactivation-feedback.php 3 years ago class-evf-admin-editor.php 4 years ago class-evf-admin-entries-table-list.php 3 years ago class-evf-admin-entries.php 4 years ago class-evf-admin-form-templates.php 3 years ago class-evf-admin-forms-table-list.php 3 years ago class-evf-admin-forms.php 3 years ago class-evf-admin-import-export.php 4 years ago class-evf-admin-menus.php 2 years ago class-evf-admin-notices.php 3 years ago class-evf-admin-settings.php 2 years ago class-evf-admin-tools.php 4 years ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 2 years ago evf-admin-functions.php 3 years ago
class-evf-admin-settings.php
947 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 if ( empty( self::$settings ) ) {
44 $settings = array();
45
46 include_once dirname( __FILE__ ) . '/settings/class-evf-settings-page.php';
47
48 $settings[] = include 'settings/class-evf-settings-general.php';
49 $settings[] = include 'settings/class-evf-settings-recaptcha.php';
50 $settings[] = include 'settings/class-evf-settings-email.php';
51 $settings[] = include 'settings/class-evf-settings-validation.php';
52 $settings[] = include 'settings/class-evf-settings-misc.php';
53 $settings[] = include 'settings/class-evf-settings-integrations.php';
54
55 self::$settings = apply_filters( 'everest_forms_get_settings_pages', $settings );
56 }
57
58 return self::$settings;
59 }
60
61 /**
62 * Save the settings.
63 */
64 public static function save() {
65 global $current_tab;
66
67 check_admin_referer( 'everest-forms-settings' );
68
69 // Trigger actions.
70 do_action( 'everest_forms_settings_save_' . $current_tab );
71 do_action( 'everest_forms_update_options_' . $current_tab );
72 do_action( 'everest_forms_update_options' );
73 $flag = apply_filters( 'show_everest_forms_setting_message', true );
74 if ( $flag ) {
75 self::add_message( esc_html__( 'Your settings have been saved.', 'everest-forms' ) );
76 }
77
78 // Clear any unwanted data and flush rules.
79 update_option( 'everest_forms_queue_flush_rewrite_rules', 'yes' );
80
81 do_action( 'everest_forms_settings_saved' );
82 }
83
84 /**
85 * Add a message.
86 *
87 * @param string $text Message.
88 */
89 public static function add_message( $text ) {
90 self::$messages[] = $text;
91 }
92
93 /**
94 * Add an error.
95 *
96 * @param string $text Message.
97 */
98 public static function add_error( $text ) {
99 self::$errors[] = $text;
100 }
101
102 /**
103 * Output messages + errors.
104 */
105 public static function show_messages() {
106 if ( count( self::$errors ) > 0 ) {
107 foreach ( self::$errors as $error ) {
108 echo '<div id="message" class="error inline"><p><strong>' . wp_kses_post( $error ) . '</strong></p></div>';
109 }
110 } elseif ( count( self::$messages ) > 0 ) {
111 foreach ( self::$messages as $message ) {
112 echo '<div id="message" class="updated inline"><p><strong>' . esc_html( $message ) . '</strong></p></div>';
113 }
114 }
115 }
116
117 /**
118 * Settings page.
119 *
120 * Handles the display of the main everest-forms settings page in admin.
121 */
122 public static function output() {
123 global $current_section, $current_tab;
124
125 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
126
127 do_action( 'everest_forms_settings_start' );
128
129 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 );
130
131 wp_localize_script(
132 'everest_forms_settings',
133 'everest_forms_settings_params',
134 array(
135 'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'everest-forms' ),
136 )
137 );
138
139 // Get tabs for the settings page.
140 $tabs = apply_filters( 'everest_forms_settings_tabs_array', array() );
141
142 include dirname( __FILE__ ) . '/views/html-admin-settings.php';
143 }
144
145 /**
146 * Get a setting from the settings API.
147 *
148 * @param string $option_name Option name.
149 * @param mixed $default Default value.
150 * @return mixed
151 */
152 public static function get_option( $option_name, $default = '' ) {
153 if ( ! $option_name ) {
154 return $default;
155 }
156
157 // Array value.
158 if ( strstr( $option_name, '[' ) ) {
159
160 parse_str( $option_name, $option_array );
161
162 // Option name is first key.
163 $option_name = current( array_keys( $option_array ) );
164
165 // Get value.
166 $option_values = get_option( $option_name, '' );
167
168 $key = key( $option_array[ $option_name ] );
169
170 if ( isset( $option_values[ $key ] ) ) {
171 $option_value = $option_values[ $key ];
172 } else {
173 $option_value = null;
174 }
175 } else {
176 // Single value.
177 $option_value = get_option( $option_name, null );
178 }
179
180 if ( is_array( $option_value ) ) {
181 $option_value = array_map( 'stripslashes', $option_value );
182 } elseif ( ! is_null( $option_value ) ) {
183 $option_value = stripslashes( $option_value );
184 }
185
186 return ( null === $option_value ) ? $default : $option_value;
187 }
188
189 /**
190 * Output admin fields.
191 *
192 * Loops though the everest-forms options array and outputs each field.
193 *
194 * @param array[] $options Opens array to output.
195 */
196 public static function output_fields( $options ) {
197 foreach ( $options as $value ) {
198 if ( ! isset( $value['type'] ) ) {
199 continue;
200 }
201 if ( ! isset( $value['id'] ) ) {
202 $value['id'] = '';
203 }
204 if ( ! isset( $value['title'] ) ) {
205 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
206 }
207 if ( ! isset( $value['class'] ) ) {
208 $value['class'] = '';
209 }
210 if ( ! isset( $value['css'] ) ) {
211 $value['css'] = '';
212 }
213 if ( ! isset( $value['default'] ) ) {
214 $value['default'] = '';
215 }
216 if ( ! isset( $value['desc'] ) ) {
217 $value['desc'] = '';
218 }
219 if ( ! isset( $value['desc_tip'] ) ) {
220 $value['desc_tip'] = false;
221 }
222 if ( ! isset( $value['placeholder'] ) ) {
223 $value['placeholder'] = '';
224 }
225 if ( ! isset( $value['suffix'] ) ) {
226 $value['suffix'] = '';
227 }
228 if ( ! isset( $value['value'] ) ) {
229 $value['value'] = self::get_option( $value['id'], $value['default'] );
230 }
231
232 // Custom attribute handling.
233 $custom_attributes = array();
234
235 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
236 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
237 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
238 }
239 }
240
241 // Description handling.
242 $field_description = self::get_field_description( $value );
243 $description = $field_description['description'];
244 $tooltip_html = $field_description['tooltip_html'];
245
246 // Switch based on type.
247 switch ( $value['type'] ) {
248
249 // Section Titles.
250 case 'title':
251 if ( ! empty( $value['title'] ) ) {
252 echo '<h2>' . esc_html( $value['title'] ) . '</h2>';
253 }
254 if ( ! empty( $value['desc'] ) ) {
255 echo wp_kses_post( wpautop( wptexturize( $value['desc'] ) ) );
256 }
257 echo '<table class="form-table">' . "\n\n";
258 if ( ! empty( $value['id'] ) ) {
259 do_action( 'everest_forms_settings_' . sanitize_title( $value['id'] ) );
260 }
261 break;
262
263 // Section Ends.
264 case 'sectionend':
265 if ( ! empty( $value['id'] ) ) {
266 do_action( 'everest_forms_settings_' . sanitize_title( $value['id'] ) . '_end' );
267 }
268 echo '</table>';
269 if ( ! empty( $value['id'] ) ) {
270 do_action( 'everest_forms_settings_' . sanitize_title( $value['id'] ) . '_after' );
271 }
272 break;
273
274 // Standard text inputs and subtypes like 'number'.
275 case 'text':
276 case 'password':
277 case 'datetime':
278 case 'datetime-local':
279 case 'date':
280 case 'date-time':
281 case 'month':
282 case 'time':
283 case 'week':
284 case 'number':
285 case 'email':
286 case 'url':
287 case 'tel':
288 $option_value = $value['value'];
289 $visibility_class = array();
290
291 if ( isset( $value['is_visible'] ) ) {
292 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
293 }
294
295 if ( empty( $option_value ) ) {
296 $option_value = $value['default'];
297 }
298
299 ?><tr valign="top" class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
300 <th scope="row" class="titledesc">
301 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
302 </th>
303 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
304 <input
305 name="<?php echo esc_attr( $value['id'] ); ?>"
306 id="<?php echo esc_attr( $value['id'] ); ?>"
307 type="<?php echo esc_attr( $value['type'] ); ?>"
308 style="<?php echo esc_attr( $value['css'] ); ?>"
309 value="<?php echo esc_attr( $option_value ); ?>"
310 class="<?php echo esc_attr( $value['class'] ); ?>"
311 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
312 <?php
313 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
314 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
315 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
316 }
317 }
318 ?>
319 /><?php echo esc_html( $value['suffix'] ); ?> <?php echo wp_kses_post( $description ); ?>
320 </td>
321 </tr>
322 <?php
323 break;
324 case 'image':
325 $option_value = $value['value'];
326 if ( empty( $option_value ) ) {
327 $option_value = $value['default'];
328 }
329 $visibility_class = array();
330 if ( isset( $value['is_visible'] ) ) {
331 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
332 }
333
334 $upload_text = __( 'Upload Logo', 'everest-forms' );
335 $alt_text = __( 'Header Logo', 'everest-forms' );
336 if ( 'everest_forms_pdf_background_image' === $value['id'] ) {
337 $upload_text = __( 'Upload Image', 'everest-forms' );
338 $alt_text = __( 'Background Image', 'everest-forms' );
339 }
340
341 ?>
342 <tr valign="top">
343 <th scope="row" class="titledesc">
344 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
345 </th>
346 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
347 <img src="<?php echo esc_attr( $option_value ); ?>" alt="<?php echo esc_attr( $alt_text ); ?>" class="evf-image-uploader <?php echo empty( $option_value ) ? 'everest-forms-hidden' : ''; ?>" height="100" width="auto">
348 <button type="button" class="evf-image-uploader evf-button button-secondary" <?php echo empty( $option_value ) ? '' : 'style="display:none"'; ?> ><?php echo esc_html( $upload_text ); ?></button>
349 <input
350 name="<?php echo esc_attr( $value['id'] ); ?>"
351 id="<?php echo esc_attr( $value['id'] ); ?>"
352 value="<?php echo esc_attr( $option_value ); ?>"
353 type="hidden"
354 >
355 <?php
356 // Adding scripts.
357 wp_enqueue_script( 'jquery' );
358 wp_enqueue_media();
359 wp_enqueue_script( 'evf-file-uploader' );
360 break;
361 // Color picker.
362 case 'color':
363 $option_value = $value['value'];
364
365 ?>
366 <tr valign="top">
367 <th scope="row" class="titledesc">
368 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
369 </th>
370 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">&lrm;
371 <span class="colorpickpreview" style="background: <?php echo esc_attr( $option_value ); ?>">&nbsp;</span>
372 <input
373 name="<?php echo esc_attr( $value['id'] ); ?>"
374 id="<?php echo esc_attr( $value['id'] ); ?>"
375 type="text"
376 dir="ltr"
377 style="<?php echo esc_attr( $value['css'] ); ?>"
378 value="<?php echo esc_attr( $option_value ); ?>"
379 class="<?php echo esc_attr( $value['class'] ); ?>colorpick"
380 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
381 <?php
382 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
383 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
384 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
385 }
386 }
387 ?>
388 />&lrm; <?php echo wp_kses_post( $description ); ?>
389 <div id="colorPickerDiv_<?php echo esc_attr( $value['id'] ); ?>" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>
390 </td>
391 </tr>
392 <?php
393 break;
394
395 // Textarea.
396 case 'textarea':
397 $option_value = $value['value'];
398
399 ?>
400 <tr valign="top">
401 <th scope="row" class="titledesc">
402 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
403 </th>
404 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
405 <?php echo wp_kses_post( $description ); ?>
406
407 <textarea
408 name="<?php echo esc_attr( $value['id'] ); ?>"
409 id="<?php echo esc_attr( $value['id'] ); ?>"
410 style="<?php echo esc_attr( $value['css'] ); ?>"
411 class="<?php echo esc_attr( $value['class'] ); ?>"
412 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
413 <?php
414 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
415 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
416 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
417 }
418 }
419 ?>
420 ><?php echo esc_textarea( $option_value ); ?></textarea>
421 </td>
422 </tr>
423 <?php
424 break;
425
426 // Select boxes.
427 case 'select':
428 case 'multiselect':
429 $option_value = $value['value'];
430
431 ?>
432 <tr valign="top">
433 <th scope="row" class="titledesc">
434 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
435 </th>
436 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
437 <select
438 name="<?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
439 id="<?php echo esc_attr( $value['id'] ); ?>"
440 style="<?php echo esc_attr( $value['css'] ); ?>"
441 class="<?php echo esc_attr( $value['class'] ); ?>"
442 <?php
443 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
444 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
445 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
446 }
447 }
448 ?>
449 <?php echo 'multiselect' === $value['type'] ? 'multiple="multiple"' : ''; ?>
450 >
451 <?php
452 foreach ( $value['options'] as $key => $val ) {
453 ?>
454 <option value="<?php echo esc_attr( $key ); ?>"
455 <?php
456
457 if ( is_array( $option_value ) ) {
458 selected( in_array( (string) $key, $option_value, true ), true );
459 } else {
460 selected( $option_value, (string) $key );
461 }
462
463 ?>
464 >
465 <?php echo esc_html( $val ); ?></option>
466 <?php
467 }
468 ?>
469 </select> <?php echo wp_kses_post( $description ); ?>
470 </td>
471 </tr>
472 <?php
473 break;
474
475 // Radio inputs.
476 case 'radio':
477 $option_value = $value['value'];
478
479 ?>
480 <tr valign="top">
481 <th scope="row" class="titledesc">
482 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
483 </th>
484 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
485 <fieldset>
486 <?php echo wp_kses_post( $description ); ?>
487 <ul class="<?php echo esc_attr( $value['class'] ); ?>">
488 <?php
489 foreach ( $value['options'] as $key => $val ) {
490 ?>
491 <li>
492 <label><input
493 name="<?php echo esc_attr( $value['id'] ); ?>"
494 id="<?php echo esc_attr( $value['id'] ); ?>"
495 value="<?php echo esc_attr( $key ); ?>"
496 type="radio"
497 style="<?php echo esc_attr( $value['css'] ); ?>"
498 class="<?php echo esc_attr( $value['class'] ); ?>"
499 <?php
500 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
501 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
502 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
503 }
504 }
505 ?>
506 <?php checked( $key, $option_value ); ?>
507 /> <?php echo esc_html( $val ); ?></label>
508 </li>
509 <?php
510 }
511 ?>
512 </ul>
513 </fieldset>
514 </td>
515 </tr>
516 <?php
517 break;
518
519 // Toggle input.
520 case 'toggle':
521 $option_value = $value['value'];
522
523 if ( empty( $option_value ) ) {
524 $option_value = $value['default'];
525 }
526 ?>
527 <tr valign="top">
528 <th scope="row" class="titledesc">
529 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
530 </th>
531 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
532 <?php echo wp_kses_post( $description ); ?>
533 <div class="evf-toggle-section">
534 <span class="everest-forms-toggle-form">
535 <input
536 type="checkbox"
537 name="<?php echo esc_attr( $value['id'] ); ?>"
538 id="<?php echo esc_attr( $value['id'] ); ?>"
539 style="<?php echo esc_attr( $value['css'] ); ?>"
540 class="<?php echo esc_attr( $value['class'] ); ?>"
541 value="yes"
542 <?php checked( 'yes', $option_value, true ); ?>
543 >
544 <span class="slider round"></span>
545 </span>
546 </div>
547 </td>
548 </tr>
549 <?php
550 break;
551
552 // Radio image inputs.
553 case 'radio-image':
554 $option_value = $value['value'];
555
556 ?>
557 <tr valign="top">
558 <th scope="row" class="titledesc">
559 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
560 </th>
561 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
562 <fieldset>
563 <ul>
564 <?php
565 foreach ( $value['options'] as $key => $val ) {
566 ?>
567 <li>
568 <label>
569 <img src="<?php echo esc_html( $val['image'] ); ?>">
570 <input
571 name="<?php echo esc_attr( $value['id'] ); ?>"
572 value="<?php echo esc_attr( $key ); ?>"
573 type="radio"
574 style="<?php echo esc_attr( $value['css'] ); ?>"
575 class="<?php echo esc_attr( $value['class'] ); ?>"
576 <?php
577 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
578 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
579 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
580 }
581 }
582 ?>
583 <?php checked( $key, $option_value ); ?>
584 />
585 <?php echo esc_html( $val['name'] ); ?></label>
586 </li>
587 <?php
588 }
589 ?>
590 </ul>
591 <?php echo wp_kses_post( $description ); ?>
592 </fieldset>
593 </td>
594 </tr>
595 <?php
596 break;
597
598 // Checkbox input.
599 case 'checkbox':
600 $option_value = $value['value'];
601 $visibility_class = array();
602
603 if ( ! isset( $value['hide_if_checked'] ) ) {
604 $value['hide_if_checked'] = false;
605 }
606 if ( ! isset( $value['show_if_checked'] ) ) {
607 $value['show_if_checked'] = false;
608 }
609 if ( 'yes' === $value['hide_if_checked'] || 'yes' === $value['show_if_checked'] ) {
610 $visibility_class[] = 'hidden_option';
611 }
612 if ( 'option' === $value['hide_if_checked'] ) {
613 $visibility_class[] = 'hide_options_if_checked';
614 }
615 if ( 'option' === $value['show_if_checked'] ) {
616 $visibility_class[] = 'show_options_if_checked';
617 }
618 if ( isset( $value['is_visible'] ) ) {
619 $visibility_class[] = $value['is_visible'] ? 'everest-forms-visible' : 'everest-forms-hidden';
620 }
621
622 if ( ! isset( $value['checkboxgroup'] ) || 'start' === $value['checkboxgroup'] ) {
623 ?>
624 <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
625 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
626 <td class="forminp forminp-checkbox">
627 <fieldset>
628 <?php
629 } else {
630 ?>
631 <fieldset class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
632 <?php
633 }
634
635 if ( ! empty( $value['title'] ) ) {
636 ?>
637 <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ); ?></span></legend>
638 <?php
639 }
640
641 ?>
642 <label for="<?php echo esc_attr( $value['id'] ); ?>">
643 <input
644 name="<?php echo esc_attr( $value['id'] ); ?>"
645 id="<?php echo esc_attr( $value['id'] ); ?>"
646 type="checkbox"
647 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
648 value="1"
649 <?php checked( $option_value, 'yes' ); ?>
650 <?php
651 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
652 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
653 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
654 }
655 }
656 ?>
657 />
658 <?php echo wp_kses_post( $description ); ?>
659 </label> <?php echo wp_kses_post( $tooltip_html ); ?>
660 <?php
661
662 if ( ! isset( $value['checkboxgroup'] ) || 'end' === $value['checkboxgroup'] ) {
663 ?>
664 </fieldset>
665 </td>
666 </tr>
667 <?php
668 } else {
669 ?>
670 </fieldset>
671 <?php
672 }
673 break;
674
675 // Single page selects.
676 case 'single_select_page':
677 $args = array(
678 'name' => $value['id'],
679 'id' => $value['id'],
680 'sort_column' => 'menu_order',
681 'sort_order' => 'ASC',
682 'show_option_none' => ' ',
683 'class' => $value['class'],
684 'echo' => false,
685 'selected' => absint( $value['value'] ),
686 'post_status' => 'publish,private,draft',
687 );
688
689 if ( isset( $value['args'] ) ) {
690 $args = wp_parse_args( $value['args'], $args );
691 }
692
693 ?>
694 <tr valign="top" class="single_select_page">
695 <th scope="row" class="titledesc">
696 <label><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
697 </th>
698 <td class="forminp">
699 <?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 ) ) ); ?> <?php echo wp_kses_post( $description ); ?>
700 </td>
701 </tr>
702 <?php
703 break;
704
705 // Days/months/years selector.
706 case 'relative_date_selector':
707 $periods = array(
708 'days' => __( 'Day(s)', 'everest-forms' ),
709 'weeks' => __( 'Week(s)', 'everest-forms' ),
710 'months' => __( 'Month(s)', 'everest-forms' ),
711 'years' => __( 'Year(s)', 'everest-forms' ),
712 );
713 $option_value = evf_parse_relative_date_option( $value['value'] );
714 ?>
715 <tr valign="top">
716 <th scope="row" class="titledesc">
717 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
718 </th>
719 <td class="forminp">
720 <input
721 name="<?php echo esc_attr( $value['id'] ); ?>[number]"
722 id="<?php echo esc_attr( $value['id'] ); ?>"
723 type="number"
724 style="width: 80px;"
725 value="<?php echo esc_attr( $option_value['number'] ); ?>"
726 class="<?php echo esc_attr( $value['class'] ); ?>"
727 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
728 step="1"
729 min="1"
730 <?php
731 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
732 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
733 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
734 }
735 }
736 ?>
737 />&nbsp;
738 <select name="<?php echo esc_attr( $value['id'] ); ?>[unit]" style="width: auto;">
739 <?php
740 foreach ( $periods as $value => $label ) {
741 echo '<option value="' . esc_attr( $value ) . '"' . selected( $option_value['unit'], $value, false ) . '>' . esc_html( $label ) . '</option>';
742 }
743 ?>
744 </select> <?php echo ( $description ) ? wp_kses_post( $description ) : ''; ?>
745 </td>
746 </tr>
747 <?php
748 break;
749 // For anchor tag.
750 case 'link':
751 ?>
752 <tr valign="top">
753 <th scope="row" class="titledesc">
754 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></label>
755 </th>
756 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
757 <?php
758 if ( isset( $value['buttons'] ) && is_array( $value['buttons'] ) ) {
759 foreach ( $value['buttons'] as $button ) {
760 ?>
761 <a href="<?php echo esc_url( $button['href'] ); ?>" class="button <?php echo esc_attr( $button['class'] ); ?>"
762 style="<?php echo esc_attr( $value['css'] ); ?>"
763 <?php
764 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
765 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
766 echo esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
767 }
768 }
769 ?>
770 >
771 <?php echo esc_html( $button['title'] ); ?>
772 </a>
773 <?php
774 }
775 }
776 ?>
777 <?php echo esc_html( $value['suffix'] ); ?> <?php echo wp_kses_post( $description ); ?>
778 </td>
779 </tr>
780 <?php
781 break;
782
783 // Default: run an action.
784 default:
785 do_action( 'everest_forms_admin_field_' . $value['type'], $value );
786 break;
787 }
788 }
789 }
790
791 /**
792 * Helper function to get the formatted description and tip HTML for a
793 * given form field. Plugins can call this when implementing their own custom
794 * settings types.
795 *
796 * @param array $value The form field value array.
797 * @return array The description and tip as a 2 element array.
798 */
799 public static function get_field_description( $value ) {
800 $description = '';
801 $tooltip_html = '';
802
803 if ( true === $value['desc_tip'] ) {
804 $tooltip_html = $value['desc'];
805 } elseif ( ! empty( $value['desc_tip'] ) ) {
806 $description = $value['desc'];
807 $tooltip_html = $value['desc_tip'];
808 } elseif ( ! empty( $value['desc'] ) ) {
809 $description = $value['desc'];
810 }
811
812 if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ), true ) ) {
813 $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
814 } elseif ( $description && in_array( $value['type'], array( 'checkbox' ), true ) ) {
815 $description = wp_kses_post( $description );
816 } elseif ( $description ) {
817 $description = '<p class="description">' . wp_kses_post( $description ) . '</p>';
818 }
819
820 if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ), true ) ) {
821 $tooltip_html = '<p class="description">' . $tooltip_html . '</p>';
822 } elseif ( $tooltip_html ) {
823 $tooltip_html = evf_help_tip( $tooltip_html );
824 }
825
826 return array(
827 'description' => $description,
828 'tooltip_html' => $tooltip_html,
829 );
830 }
831
832 /**
833 * Save admin fields.
834 *
835 * Loops though the everest-forms options array and outputs each field.
836 *
837 * @param array $options Options array to output.
838 * @param array $data Optional. Data to use for saving. Defaults to $_POST.
839 * @return bool
840 */
841 public static function save_fields( $options, $data = null ) {
842 if ( is_null( $data ) ) {
843 $data = $_POST; // phpcs:ignore WordPress.Security.NonceVerification
844 }
845 if ( empty( $data ) ) {
846 return false;
847 }
848
849 // Options to update will be stored here and saved later.
850 $update_options = array();
851 $autoload_options = array();
852
853 // Loop options and get values to save.
854 foreach ( $options as $option ) {
855 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) || ( isset( $option['is_option'] ) && false === $option['is_option'] ) ) {
856 continue;
857 }
858
859 // Get posted value.
860 if ( strstr( $option['id'], '[' ) ) {
861 parse_str( $option['id'], $option_name_array );
862 $option_name = current( array_keys( $option_name_array ) );
863 $setting_name = key( $option_name_array[ $option_name ] );
864 $raw_value = isset( $data[ $option_name ][ $setting_name ] ) ? wp_unslash( $data[ $option_name ][ $setting_name ] ) : null;
865 } else {
866 $option_name = $option['id'];
867 $setting_name = '';
868 $raw_value = isset( $data[ $option['id'] ] ) ? wp_unslash( $data[ $option['id'] ] ) : null;
869 }
870
871 // Format the value based on option type.
872 switch ( $option['type'] ) {
873 case 'checkbox':
874 $value = '1' === $raw_value || 'yes' === $raw_value ? 'yes' : 'no';
875 break;
876 case 'toggle':
877 $value = '1' === $raw_value || 'yes' === $raw_value ? 'yes' : 'no';
878 break;
879 case 'textarea':
880 $value = wp_kses_post( trim( $raw_value ) );
881 break;
882 case 'select':
883 $allowed_values = empty( $option['options'] ) ? array() : array_map( 'strval', array_keys( $option['options'] ) );
884 if ( empty( $option['default'] ) && empty( $allowed_values ) ) {
885 $value = null;
886 break;
887 }
888 $default = ( empty( $option['default'] ) ? $allowed_values[0] : $option['default'] );
889 $value = in_array( $raw_value, $allowed_values, true ) ? $raw_value : $default;
890 break;
891 default:
892 $value = evf_clean( $raw_value );
893 break;
894 }
895
896 /**
897 * Sanitize the value of an option.
898 *
899 * @since 1.0.0
900 */
901 $value = apply_filters( 'everest_forms_admin_settings_sanitize_option', $value, $option, $raw_value );
902
903 /**
904 * Sanitize the value of an option by option name.
905 *
906 * @since 1.0.0
907 */
908 $value = apply_filters( "everest_forms_admin_settings_sanitize_option_$option_name", $value, $option, $raw_value );
909
910 if ( is_null( $value ) ) {
911 continue;
912 }
913
914 // Check if option is an array and handle that differently to single values.
915 if ( $option_name && $setting_name ) {
916 if ( ! isset( $update_options[ $option_name ] ) ) {
917 $update_options[ $option_name ] = get_option( $option_name, array() );
918 }
919 if ( ! is_array( $update_options[ $option_name ] ) ) {
920 $update_options[ $option_name ] = array();
921 }
922 $update_options[ $option_name ][ $setting_name ] = $value;
923 } else {
924 $update_options[ $option_name ] = $value;
925 }
926
927 $autoload_options[ $option_name ] = isset( $option['autoload'] ) ? (bool) $option['autoload'] : true;
928
929 /**
930 * Fire an action before saved.
931 *
932 * @deprecated 1.2.0 - doesn't allow manipulation of values!
933 */
934 do_action( 'everest_forms_update_option', $option );
935 }
936
937 // Save all options in our array.
938 foreach ( $update_options as $name => $value ) {
939 update_option( $name, $value, $autoload_options[ $name ] ? 'yes' : 'no' );
940 }
941
942 return true;
943 }
944 }
945
946 endif;
947