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