class-evf-setting-utilities.php
3 months ago
class-evf-settings-advanced.php
4 weeks ago
class-evf-settings-email.php
4 weeks ago
class-evf-settings-general.php
3 months ago
class-evf-settings-integrations.php
3 months ago
class-evf-settings-page.php
3 months ago
class-evf-settings-payments.php
4 weeks ago
class-evf-settings-reporting.php
2 years ago
class-evf-settings-security.php
3 months ago
class-evf-settings-validation.php
11 months ago
class-evf-settings-integrations.php
607 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Integration Settings |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @since 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( class_exists( 'EVF_Settings_Integrations', false ) ) { |
| 12 | return new EVF_Settings_Integrations(); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * EVF_Settings_Integrations. |
| 17 | */ |
| 18 | class EVF_Settings_Integrations extends EVF_Settings_Page { |
| 19 | |
| 20 | /** |
| 21 | * Minimum Pro version that supports the new category UI. |
| 22 | * Bump when a new Pro release changes the rendering contract. |
| 23 | * |
| 24 | * @since 1.x.0 |
| 25 | * @var string |
| 26 | */ |
| 27 | const PRO_NEW_UI_VERSION = '1.9.13'; |
| 28 | |
| 29 | /** |
| 30 | * Constructor. |
| 31 | */ |
| 32 | public function __construct() { |
| 33 | $this->id = 'integration'; |
| 34 | $this->label = esc_html__( 'Integration', 'everest-forms' ); |
| 35 | |
| 36 | if ( isset( evf()->integrations ) && evf()->integrations->get_integrations() ) { |
| 37 | parent::__construct(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns true when Everest Forms Pro is active. |
| 43 | * |
| 44 | * @return bool |
| 45 | */ |
| 46 | protected function is_pro_active() { |
| 47 | return defined( 'EFP_VERSION' ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns true when the active Pro version supports the new category UI. |
| 52 | * Falls back to true when Pro is not installed (upsell-only mode). |
| 53 | * |
| 54 | * @return bool |
| 55 | */ |
| 56 | protected function pro_supports_new_ui() { |
| 57 | if ( ! $this->is_pro_active() ) { |
| 58 | return true; |
| 59 | } |
| 60 | return version_compare( EFP_VERSION, self::PRO_NEW_UI_VERSION, '>=' ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Output the settings page. |
| 65 | */ |
| 66 | public function output() { |
| 67 | global $current_section; |
| 68 | |
| 69 | $GLOBALS['hide_save_button'] = true; |
| 70 | $integrations = evf()->integrations->get_integrations(); |
| 71 | |
| 72 | if ( ! $this->pro_supports_new_ui() ) { |
| 73 | if ( '' === $current_section ) { |
| 74 | $this->output_integrations_legacy( $integrations ); |
| 75 | } elseif ( isset( $integrations[ $current_section ] ) ) { |
| 76 | $integrations[ $current_section ]->output_integration(); |
| 77 | } |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | // Legacy deep-link: ?section=<integration_id> (no cat- prefix). |
| 82 | if ( |
| 83 | ! empty( $current_section ) |
| 84 | && ! str_starts_with( $current_section, 'cat-' ) |
| 85 | && isset( $integrations[ $current_section ] ) |
| 86 | ) { |
| 87 | $integrations[ $current_section ]->output_integration(); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | $this->output_integrations( $integrations ); |
| 92 | $GLOBALS['hide_save_button'] = true; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Suppress the global Save button. |
| 97 | */ |
| 98 | public function save_button() {} |
| 99 | |
| 100 | /** |
| 101 | * Handle save for the active category. |
| 102 | */ |
| 103 | public function save() { |
| 104 | global $current_section; |
| 105 | |
| 106 | if ( empty( $current_section ) || ! str_starts_with( $current_section, 'cat-' ) ) { |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | if ( |
| 111 | ! isset( $_POST['_wpnonce'] ) || |
| 112 | ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'everest-forms-settings' ) |
| 113 | ) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | $grouped = $this->group_integrations_by_category( evf()->integrations->get_integrations() ); |
| 118 | $active_category = null; |
| 119 | |
| 120 | foreach ( array_keys( $grouped ) as $category ) { |
| 121 | if ( $this->category_to_slug( $category ) === $current_section ) { |
| 122 | $active_category = $category; |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if ( null === $active_category || empty( $grouped[ $active_category ] ) ) { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | $submitted_id = isset( $_POST['_evf_integration_id'] ) |
| 132 | ? sanitize_text_field( wp_unslash( $_POST['_evf_integration_id'] ) ) |
| 133 | : ''; |
| 134 | |
| 135 | foreach ( $grouped[ $active_category ] as $integration ) { |
| 136 | if ( $this->is_upsell_integration( $integration ) ) { |
| 137 | continue; |
| 138 | } |
| 139 | if ( $submitted_id && $integration->id !== $submitted_id ) { |
| 140 | continue; |
| 141 | } |
| 142 | if ( method_exists( $integration, 'save' ) ) { |
| 143 | $integration->save(); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // ------------------------------------------------------------------------- |
| 149 | // Legacy flat-list UI (Pro < PRO_NEW_UI_VERSION) |
| 150 | // ------------------------------------------------------------------------- |
| 151 | |
| 152 | /** |
| 153 | * Renders the original flat integration list. |
| 154 | * Identical to the pre-category implementation — nothing changed. |
| 155 | * |
| 156 | * @param array $integrations |
| 157 | */ |
| 158 | protected function output_integrations_legacy( $integrations ) { |
| 159 | ?> |
| 160 | <div class="everest-forms-options-header"> |
| 161 | <div class="everest-forms-options-header--top"> |
| 162 | <span class="evf-forms-options-header-header--top-icon"> |
| 163 | <?php echo evf_file_get_contents( '/assets/images/settings-icons/integration.svg' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 164 | </span> |
| 165 | <h3><?php esc_html_e( 'Integrations', 'everest-forms' ); ?></h3> |
| 166 | </div> |
| 167 | </div> |
| 168 | <div class="everest-forms-integrations-connection"> |
| 169 | <?php foreach ( $integrations as $integration ) : ?> |
| 170 | <div class="everest-forms-integrations" |
| 171 | data-action="<?php echo esc_attr( isset( $integration->upgrade ) ? $integration->upgrade : '' ); ?>" |
| 172 | data-links="<?php echo esc_attr( isset( $integration->vedio_id ) ? $integration->vedio_id : '' ); ?>"> |
| 173 | <div class="integration-header-info"> |
| 174 | <div class="integration-status"> |
| 175 | <span class="toggle-switch-outer <?php echo esc_attr( $integration->account_status ); ?>"></span> |
| 176 | </div> |
| 177 | <div class="integration-detail"> |
| 178 | <figure class="logo"> |
| 179 | <img src="<?php echo esc_url( $integration->icon ); ?>" |
| 180 | alt="<?php echo esc_attr( $integration->method_title ); ?>"> |
| 181 | </figure> |
| 182 | <div class="integration-info"> |
| 183 | <a href="<?php echo esc_url( admin_url( 'admin.php?page=evf-settings&tab=integration§ion=' . $integration->id ) ); ?>"> |
| 184 | <h3><?php echo esc_html( $integration->method_title ); ?></h3> |
| 185 | </a> |
| 186 | <p><?php echo esc_html( $integration->method_description ); ?></p> |
| 187 | </div> |
| 188 | </div> |
| 189 | </div> |
| 190 | <div class="integartion-action"> |
| 191 | <a class="integration-setup" |
| 192 | href="<?php echo esc_url( admin_url( 'admin.php?page=evf-settings&tab=integration§ion=' . $integration->id ) ); ?>"> |
| 193 | <span class="evf-icon evf-icon-setting-cog"></span> |
| 194 | </a> |
| 195 | </div> |
| 196 | </div> |
| 197 | <?php endforeach; ?> |
| 198 | </div> |
| 199 | <?php |
| 200 | } |
| 201 | |
| 202 | // ------------------------------------------------------------------------- |
| 203 | // New category sidebar UI (Pro >= PRO_NEW_UI_VERSION, or no Pro) |
| 204 | // ------------------------------------------------------------------------- |
| 205 | |
| 206 | /** |
| 207 | * @return array<string, string> |
| 208 | */ |
| 209 | protected function get_legacy_category_map() { |
| 210 | return apply_filters( 'everest_forms_integration_categories', array() ); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @return string[] |
| 215 | */ |
| 216 | protected function get_category_order() { |
| 217 | return apply_filters( |
| 218 | 'everest_forms_integration_category_order', |
| 219 | array( |
| 220 | esc_html__( 'CRM', 'everest-forms' ), |
| 221 | esc_html__( 'Email Marketing', 'everest-forms' ), |
| 222 | esc_html__( 'Cloud Storage', 'everest-forms' ), |
| 223 | esc_html__( 'SMS Notifications', 'everest-forms' ), |
| 224 | esc_html__( 'Google Sheets', 'everest-forms' ), |
| 225 | esc_html__( 'Google Calendar', 'everest-forms' ), |
| 226 | esc_html__( 'Geolocation', 'everest-forms' ), |
| 227 | esc_html__( 'OpenAI', 'everest-forms' ), |
| 228 | esc_html__( 'Other', 'everest-forms' ), |
| 229 | ) |
| 230 | ); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @param array $integrations Keyed by integration ID. |
| 235 | * @return array<string, object[]> |
| 236 | */ |
| 237 | protected function group_integrations_by_category( array $integrations ) { |
| 238 | $legacy_map = $this->get_legacy_category_map(); |
| 239 | $other = esc_html__( 'Other', 'everest-forms' ); |
| 240 | $grouped = array(); |
| 241 | |
| 242 | foreach ( $integrations as $id => $integration ) { |
| 243 | if ( 'clean-talk' === $id ) { |
| 244 | continue; |
| 245 | } |
| 246 | |
| 247 | if ( ! empty( $integration->category ) ) { |
| 248 | $category = $integration->category; |
| 249 | } elseif ( isset( $legacy_map[ $id ] ) ) { |
| 250 | $category = $legacy_map[ $id ]; |
| 251 | } else { |
| 252 | $category = $other; |
| 253 | } |
| 254 | |
| 255 | $grouped[ $category ][] = $integration; |
| 256 | } |
| 257 | |
| 258 | $sorted = array(); |
| 259 | foreach ( $this->get_category_order() as $cat ) { |
| 260 | if ( isset( $grouped[ $cat ] ) ) { |
| 261 | $sorted[ $cat ] = $grouped[ $cat ]; |
| 262 | unset( $grouped[ $cat ] ); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | return array_merge( $sorted, $grouped ); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * @param string $category |
| 271 | * @return string |
| 272 | */ |
| 273 | protected function category_to_slug( $category ) { |
| 274 | return 'cat-' . sanitize_title( $category ); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @param array $grouped |
| 279 | * @return string |
| 280 | */ |
| 281 | protected function get_active_category_slug( array $grouped ) { |
| 282 | // phpcs:ignore WordPress.Security.NonceVerification |
| 283 | $section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : ''; |
| 284 | |
| 285 | if ( ! empty( $section ) && ! str_starts_with( $section, 'cat-' ) ) { |
| 286 | return $section; |
| 287 | } |
| 288 | |
| 289 | if ( ! empty( $section ) ) { |
| 290 | foreach ( array_keys( $grouped ) as $category ) { |
| 291 | if ( $this->category_to_slug( $category ) === $section ) { |
| 292 | return $section; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | $first = array_key_first( $grouped ); |
| 298 | return $first ? $this->category_to_slug( $first ) : ''; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * @param object[] $integrations |
| 303 | * @return bool |
| 304 | */ |
| 305 | protected function category_is_all_upsell( array $integrations ) { |
| 306 | foreach ( $integrations as $integration ) { |
| 307 | if ( ! $this->is_upsell_integration( $integration ) ) { |
| 308 | return false; |
| 309 | } |
| 310 | } |
| 311 | return true; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * @param object $integration |
| 316 | * @return bool |
| 317 | */ |
| 318 | protected function is_upsell_integration( $integration ) { |
| 319 | return isset( $integration->upgrade ) && 'upgrade' === $integration->upgrade; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Renders the sidebar category navigation. |
| 324 | */ |
| 325 | public function output_sections() { |
| 326 | if ( ! $this->pro_supports_new_ui() ) { |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | $grouped = $this->group_integrations_by_category( evf()->integrations->get_integrations() ); |
| 331 | $active_slug = $this->get_active_category_slug( $grouped ); |
| 332 | |
| 333 | if ( empty( $grouped ) ) { |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | $lock_icon = '<svg class="evf-sidebar-upsell-icon" width="14" height="14" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align:middle;margin-left:5px;flex-shrink:0;" aria-hidden="true"> |
| 338 | <path d="M0 2C0 0.895431 0.895431 0 2 0H18C19.1046 0 20 0.895431 20 2V18C20 19.1046 19.1046 20 18 20H2C0.895431 20 0 19.1046 0 18V2Z" fill="#FF8C39"/> |
| 339 | <path d="M10 4.1666L13.5 13.4999H6.5L10 4.1666Z" fill="#EFEFEF"/> |
| 340 | <path d="M14.9994 15.833H4.99939V14.167H14.9994V15.833ZM15.0004 13.5H5.00037L4.16638 6.5L10.0004 11.3125L15.8334 6.5L15.0004 13.5Z" fill="white"/> |
| 341 | </svg>'; |
| 342 | |
| 343 | echo '<ul class="evf-subsections">'; |
| 344 | foreach ( $grouped as $category => $items ) { |
| 345 | $slug = $this->category_to_slug( $category ); |
| 346 | $show_lock = ! $this->is_pro_active() && $this->category_is_all_upsell( $items ); |
| 347 | $url = add_query_arg( |
| 348 | array( |
| 349 | 'page' => 'evf-settings', |
| 350 | 'tab' => $this->id, |
| 351 | 'section' => $slug, |
| 352 | ), |
| 353 | admin_url( 'admin.php' ) |
| 354 | ); |
| 355 | |
| 356 | printf( |
| 357 | '<li><a href="%s" class="%s">%s%s</a></li>', |
| 358 | esc_url( $url ), |
| 359 | esc_attr( $active_slug === $slug ? 'current' : '' ), |
| 360 | esc_html( $category ), |
| 361 | $show_lock ? $lock_icon : '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 362 | ); |
| 363 | } |
| 364 | echo '</ul>'; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Initialises the API client on a Pro integration if not already set. |
| 369 | * |
| 370 | * @param object $integration |
| 371 | */ |
| 372 | protected function ensure_client_initialised( $integration ) { |
| 373 | if ( |
| 374 | property_exists( $integration, 'client' ) && |
| 375 | empty( $integration->client ) && |
| 376 | method_exists( $integration, 'get_client' ) |
| 377 | ) { |
| 378 | try { |
| 379 | $integration->client = $integration->get_client(); |
| 380 | } catch ( \Throwable $e ) { |
| 381 | // Integration form handles a missing client gracefully. |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Renders the inner connection form for a Pro integration. |
| 388 | * Only called in new-UI path where output_connection_form() exists. |
| 389 | * |
| 390 | * @param object $integration |
| 391 | */ |
| 392 | protected function render_integration_form( $integration ) { |
| 393 | if ( $this->is_upsell_integration( $integration ) ) { |
| 394 | $this->render_upsell_card( $integration ); |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | $this->ensure_client_initialised( $integration ); |
| 399 | |
| 400 | try { |
| 401 | $integration->output_connection_form(); |
| 402 | } catch ( \Throwable $e ) { |
| 403 | echo '<p>' . esc_html__( 'This integration could not be loaded. Please update the addon.', 'everest-forms' ) . '</p>'; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Renders the upsell card for a free-tier placeholder integration. |
| 409 | * |
| 410 | * @param object $integration |
| 411 | */ |
| 412 | protected function render_upsell_card( $integration ) { |
| 413 | $title = $integration->method_title ?? ''; |
| 414 | $icon = $integration->icon ?? ''; |
| 415 | $video_id = $integration->vedio_id ?? ''; |
| 416 | $upgrade_url = $integration->upgrade_url ?? 'https://wpeverest.com/wordpress-plugins/everest-forms/pricing/'; |
| 417 | $docs_url = $integration->docs_url ?? 'https://docs.everestforms.net/docs/'; |
| 418 | $features = $integration->features ?? array(); |
| 419 | ?> |
| 420 | <div class="evf-upsell-integration-card"> |
| 421 | <div class="evf-upsell-card-header"> |
| 422 | <?php if ( $icon ) : ?> |
| 423 | <span class="evf-upsell-icon"> |
| 424 | <img src="<?php echo esc_url( $icon ); ?>" alt="<?php echo esc_attr( $title ); ?>"> |
| 425 | </span> |
| 426 | <?php endif; ?> |
| 427 | <div class="evf-upsell-card-heading"> |
| 428 | <h3><?php echo esc_html( $title ); ?></h3> |
| 429 | </div> |
| 430 | <span class="evf-upsell-lock-icon"> |
| 431 | <svg width="14" height="14" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align:middle;margin-left:5px;flex-shrink:0;" aria-hidden="true"> |
| 432 | <path d="M0 2C0 0.895431 0.895431 0 2 0H18C19.1046 0 20 0.895431 20 2V18C20 19.1046 19.1046 20 18 20H2C0.895431 20 0 19.1046 0 18V2Z" fill="#FF8C39"></path> |
| 433 | <path d="M10 4.1666L13.5 13.4999H6.5L10 4.1666Z" fill="#EFEFEF"></path> |
| 434 | <path d="M14.9994 15.833H4.99939V14.167H14.9994V15.833ZM15.0004 13.5H5.00037L4.16638 6.5L10.0004 11.3125L15.8334 6.5L15.0004 13.5Z" fill="white"></path> |
| 435 | </svg> |
| 436 | </span> |
| 437 | </div> |
| 438 | |
| 439 | <?php if ( ! empty( $features ) ) : ?> |
| 440 | <hr class="evf-upsell-divider"> |
| 441 | <?php $this->render_upsell_features( $features ); ?> |
| 442 | <?php endif; ?> |
| 443 | |
| 444 | <div class="evf-upsell-actions"> |
| 445 | <a href="<?php echo esc_url( $upgrade_url ); ?>" |
| 446 | class="evf-upsell-btn evf-upsell-btn-primary" |
| 447 | target="_blank" rel="noopener noreferrer"> |
| 448 | <?php |
| 449 | printf( |
| 450 | /* translators: %s: integration name */ |
| 451 | esc_html__( 'Unlock %s — Upgrade to Pro', 'everest-forms' ), |
| 452 | esc_html( $title ) |
| 453 | ); |
| 454 | ?> |
| 455 | <svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> |
| 456 | <line x1="7" y1="17" x2="17" y2="7"/> |
| 457 | <polyline points="7 7 17 7 17 17"/> |
| 458 | </svg> |
| 459 | </a> |
| 460 | |
| 461 | <?php if ( $video_id ) : ?> |
| 462 | <a href="<?php echo esc_url( 'https://www.youtube.com/watch?v=' . $video_id ); ?>" |
| 463 | class="evf-upsell-btn evf-upsell-upgrade-trigger" |
| 464 | data-name="<?php echo esc_attr( $title ); ?>" |
| 465 | data-links="<?php echo esc_attr( $video_id ); ?>" |
| 466 | data-upgrade-url="<?php echo esc_url( $upgrade_url ); ?>"> |
| 467 | <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"> |
| 468 | <path d="M10 16.5l6-4.5-6-4.5v9zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/> |
| 469 | </svg> |
| 470 | <?php esc_html_e( 'Watch Demo', 'everest-forms' ); ?> |
| 471 | </a> |
| 472 | <?php endif; ?> |
| 473 | |
| 474 | <a href="<?php echo esc_url( $docs_url ); ?>" |
| 475 | class="evf-upsell-btn evf-upsell-btn-ghost" |
| 476 | target="_blank" rel="noopener noreferrer"> |
| 477 | <?php esc_html_e( 'View Documentation', 'everest-forms' ); ?> |
| 478 | </a> |
| 479 | </div> |
| 480 | </div> |
| 481 | <?php |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * @param string[] $features |
| 486 | */ |
| 487 | protected function render_upsell_features( array $features ) { |
| 488 | $check_icon = '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"/></svg>'; |
| 489 | |
| 490 | echo '<ul class="evf-upsell-features">'; |
| 491 | foreach ( $features as $feature ) { |
| 492 | echo '<li>' . $check_icon . esc_html( $feature ) . '</li>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 493 | } |
| 494 | echo '</ul>'; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Renders all integrations for the active category. |
| 499 | * |
| 500 | * @param array $integrations |
| 501 | */ |
| 502 | protected function output_integrations( array $integrations ) { |
| 503 | $grouped = $this->group_integrations_by_category( $integrations ); |
| 504 | $active_slug = $this->get_active_category_slug( $grouped ); |
| 505 | $active_category = array_key_first( $grouped ); |
| 506 | |
| 507 | foreach ( array_keys( $grouped ) as $category ) { |
| 508 | if ( $this->category_to_slug( $category ) === $active_slug ) { |
| 509 | $active_category = $category; |
| 510 | break; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | $items = $grouped[ $active_category ] ?? array(); |
| 515 | ?> |
| 516 | <div class="everest-forms-options-header"> |
| 517 | <div class="everest-forms-options-header--top"> |
| 518 | <span class="evf-forms-options-header-header--top-icon"> |
| 519 | <?php echo evf_file_get_contents( '/assets/images/settings-icons/integration.svg' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 520 | </span> |
| 521 | <h3><?php echo esc_html( $active_category ); ?></h3> |
| 522 | </div> |
| 523 | </div> |
| 524 | |
| 525 | <?php |
| 526 | foreach ( $items as $integration ) : |
| 527 | $GLOBALS['hide_save_button'] = true; |
| 528 | |
| 529 | if ( $this->is_upsell_integration( $integration ) ) : |
| 530 | $this->render_upsell_card( $integration ); |
| 531 | continue; |
| 532 | endif; |
| 533 | |
| 534 | $form_action = add_query_arg( |
| 535 | array( |
| 536 | 'page' => 'evf-settings', |
| 537 | 'tab' => $this->id, |
| 538 | 'section' => $active_slug, |
| 539 | ), |
| 540 | admin_url( 'admin.php' ) |
| 541 | ); |
| 542 | ?> |
| 543 | |
| 544 | <?php if ( ! empty( $integration->use_post_form ) ) : ?> |
| 545 | |
| 546 | <form method="post" action="<?php echo esc_url( $form_action ); ?>"> |
| 547 | <input type="hidden" name="_evf_integration_id" value="<?php echo esc_attr( $integration->id ); ?>"> |
| 548 | |
| 549 | <?php $this->render_integration_form( $integration ); ?> |
| 550 | |
| 551 | <?php |
| 552 | if ( empty( $GLOBALS['hide_save_button'] ) ) : |
| 553 | $save_label = apply_filters( 'everest_forms_setting_save_label', esc_attr__( 'Save Changes', 'everest-forms' ) ); |
| 554 | wp_nonce_field( 'everest-forms-settings' ); |
| 555 | ?> |
| 556 | <p class="submit"> |
| 557 | <button name="save" type="submit" |
| 558 | class="everest-forms-btn everest-forms-btn-primary everest-forms-save-button" |
| 559 | value="<?php echo esc_attr( $save_label ); ?>"> |
| 560 | <?php echo esc_html( $save_label ); ?> |
| 561 | </button> |
| 562 | </p> |
| 563 | <?php endif; ?> |
| 564 | </form> |
| 565 | |
| 566 | <?php else : ?> |
| 567 | |
| 568 | <div class="everest-forms-card"> |
| 569 | <div class="everest-forms-accordion-wrapper"> |
| 570 | <div class="everest-forms-accordion-item"> |
| 571 | <div class="everest-forms-accordion-header"> |
| 572 | <div class="everest-forms-accordion-status"> |
| 573 | <span class="toggle-switch-outer <?php echo esc_attr( $integration->account_status ); ?>"></span> |
| 574 | </div> |
| 575 | <span class="everest-forms-accordion-icon"> |
| 576 | <img src="<?php echo esc_url( $integration->icon ); ?>" |
| 577 | alt="<?php echo esc_attr( $integration->method_title ); ?>"> |
| 578 | </span> |
| 579 | <h3 class="everest-forms-accordion-title"> |
| 580 | <?php echo esc_html( $integration->method_title ); ?> |
| 581 | </h3> |
| 582 | <span class="everest-forms-accordion-toggle"> |
| 583 | <svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true"> |
| 584 | <path d="M5 7.5L10 12.5L15 7.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> |
| 585 | </svg> |
| 586 | </span> |
| 587 | </div> |
| 588 | <div class="everest-forms-accordion-content"> |
| 589 | <div class="everest-forms-accordion-content-inner"> |
| 590 | <?php $this->render_integration_form( $integration ); ?> |
| 591 | </div> |
| 592 | </div> |
| 593 | </div> |
| 594 | </div> |
| 595 | </div> |
| 596 | |
| 597 | <?php endif; ?> |
| 598 | |
| 599 | <?php |
| 600 | endforeach; |
| 601 | |
| 602 | $GLOBALS['hide_save_button'] = true; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | return new EVF_Settings_Integrations(); |
| 607 |