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