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