← All changes
|
classes/controllers/FrmOnboardingWizardController.php
+116
-67
6.30
→
6.21
View file →
| @@ -119,17 +119,15 @@ | ||
| 119 | 119 | /** |
| 120 | 120 | * Initialize hooks for template page only. |
| 121 | 121 | * |
| 122 | 122 | * @since 6.9 |
| 123 | - * | |
| 124 | - * @return void | |
| 125 | 123 | */ |
| 126 | 124 | public static function load_admin_hooks() { |
| 127 | 125 | self::set_page_url(); |
| 128 | - add_action( 'admin_init', self::class . '::do_admin_redirects' ); | |
| 126 | + add_action( 'admin_init', __CLASS__ . '::do_admin_redirects' ); | |
| 129 | 127 | |
| 130 | 128 | if ( self::has_onboarding_been_skipped() ) { |
| 131 | - add_filter( 'option_frm_inbox', self::class . '::add_wizard_to_floating_links' ); | |
| 129 | + add_filter( 'option_frm_inbox', __CLASS__ . '::add_wizard_to_floating_links' ); | |
| 132 | 130 | } |
| 133 | 131 | |
| 134 | 132 | // Load page if admin page is Onboarding Wizard. |
| 135 | 133 | self::maybe_load_page(); |
| @@ -160,9 +158,8 @@ | ||
| 160 | 158 | return; |
| 161 | 159 | } |
| 162 | 160 | |
| 163 | 161 | $transient_value = get_transient( self::TRANSIENT_NAME ); |
| 164 | - | |
| 165 | 162 | if ( ! in_array( $transient_value, array( self::TRANSIENT_VALUE, self::TRANSIENT_MULTI_VALUE ), true ) ) { |
| 166 | 163 | return; |
| 167 | 164 | } |
| 168 | 165 | |
| @@ -188,9 +185,8 @@ | ||
| 188 | 185 | } |
| 189 | 186 | |
| 190 | 187 | // Redirect to the onboarding wizard's initial step. |
| 191 | 188 | $page_url = add_query_arg( 'step', self::INITIAL_STEP, self::$page_url ); |
| 192 | - | |
| 193 | 189 | if ( wp_safe_redirect( esc_url_raw( $page_url ) ) ) { |
| 194 | 190 | exit; |
| 195 | 191 | } |
| 196 | 192 | } |
| @@ -202,23 +198,21 @@ | ||
| 202 | 198 | * |
| 203 | 199 | * @return void |
| 204 | 200 | */ |
| 205 | 201 | public static function maybe_load_page() { |
| 206 | - if ( ! self::is_onboarding_wizard_page() ) { | |
| 207 | - return; | |
| 208 | - } | |
| 202 | + if ( self::is_onboarding_wizard_page() ) { | |
| 203 | + // Dismiss the onboarding wizard message so it stops appearing after it is clicked. | |
| 204 | + $message = new FrmInbox(); | |
| 205 | + $message->dismiss( 'onboarding_wizard' ); | |
| 209 | 206 | |
| 210 | - // Dismiss the onboarding wizard message so it stops appearing after it is clicked. | |
| 211 | - $message = new FrmInbox(); | |
| 212 | - $message->dismiss( 'onboarding_wizard' ); | |
| 207 | + add_action( 'admin_menu', __CLASS__ . '::menu', 99 ); | |
| 208 | + add_action( 'admin_init', __CLASS__ . '::assign_properties' ); | |
| 209 | + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 ); | |
| 210 | + add_action( 'admin_head', __CLASS__ . '::remove_menu' ); | |
| 213 | 211 | |
| 214 | - add_action( 'admin_menu', self::class . '::menu', 99 ); | |
| 215 | - add_action( 'admin_init', self::class . '::assign_properties' ); | |
| 216 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 217 | - add_action( 'admin_head', self::class . '::remove_menu' ); | |
| 218 | - | |
| 219 | - add_filter( 'admin_body_class', self::class . '::add_admin_body_classes', 999 ); | |
| 220 | - add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 212 | + add_filter( 'admin_body_class', __CLASS__ . '::add_admin_body_classes', 999 ); | |
| 213 | + add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 214 | + } | |
| 221 | 215 | } |
| 222 | 216 | |
| 223 | 217 | /** |
| 224 | 218 | * Initializes class properties with essential values for operation. |
| @@ -259,9 +253,9 @@ | ||
| 259 | 253 | 'Formidable | ' . $label, |
| 260 | 254 | $label, |
| 261 | 255 | self::REQUIRED_CAPABILITY, |
| 262 | 256 | self::PAGE_SLUG, |
| 263 | - array( self::class, 'render' ) | |
| 257 | + array( __CLASS__, 'render' ) | |
| 264 | 258 | ); |
| 265 | 259 | } |
| 266 | 260 | |
| 267 | 261 | /** |
| @@ -317,9 +311,9 @@ | ||
| 317 | 311 | // Remove the 'FrmProSettingsController::store' action to avoid PHP errors during AJAX call. |
| 318 | 312 | remove_action( 'frm_store_settings', 'FrmProSettingsController::store' ); |
| 319 | 313 | $frm_settings->store(); |
| 320 | 314 | |
| 321 | - FrmEmailCollectionHelper::subscribe_to_active_campaign(); | |
| 315 | + self::subscribe_to_active_campaign(); | |
| 322 | 316 | |
| 323 | 317 | // Send response. |
| 324 | 318 | wp_send_json_success(); |
| 325 | 319 | } |
| @@ -324,8 +318,76 @@ | ||
| 324 | 318 | wp_send_json_success(); |
| 325 | 319 | } |
| 326 | 320 | |
| 327 | 321 | /** |
| 322 | + * When the user consents to receiving news of updates, subscribe their email to ActiveCampaign. | |
| 323 | + * | |
| 324 | + * @since 6.16 | |
| 325 | + * | |
| 326 | + * @return void | |
| 327 | + */ | |
| 328 | + private static function subscribe_to_active_campaign() { | |
| 329 | + $user = wp_get_current_user(); | |
| 330 | + if ( empty( $user->user_email ) ) { | |
| 331 | + return; | |
| 332 | + } | |
| 333 | + | |
| 334 | + if ( ! self::should_send_email_to_active_campaign( $user->user_email ) ) { | |
| 335 | + return; | |
| 336 | + } | |
| 337 | + | |
| 338 | + $user_id = $user->ID; | |
| 339 | + $first_name = get_user_meta( $user_id, 'first_name', true ); | |
| 340 | + $last_name = get_user_meta( $user_id, 'last_name', true ); | |
| 341 | + | |
| 342 | + wp_remote_post( | |
| 343 | + 'https://sandbox.formidableforms.com/api/wp-admin/admin-ajax.php?action=frm_forms_preview&form=subscribe-onboarding', | |
| 344 | + array( | |
| 345 | + 'body' => http_build_query( | |
| 346 | + array( | |
| 347 | + 'form_key' => 'subscribe-onboarding', | |
| 348 | + 'frm_action' => 'create', | |
| 349 | + 'form_id' => 5, | |
| 350 | + 'item_key' => '', | |
| 351 | + 'item_meta[0]' => '', | |
| 352 | + 'item_meta[15]' => $user->user_email, | |
| 353 | + 'item_meta[17]' => 'Source - FF Lite Plugin Onboarding', | |
| 354 | + 'item_meta[18]' => is_string( $first_name ) ? $first_name : '', | |
| 355 | + 'item_meta[19]' => is_string( $last_name ) ? $last_name : '', | |
| 356 | + ) | |
| 357 | + ), | |
| 358 | + ) | |
| 359 | + ); | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * Try to skip any fake emails. | |
| 364 | + * | |
| 365 | + * @since 6.16 | |
| 366 | + * | |
| 367 | + * @param string $email | |
| 368 | + * @return bool | |
| 369 | + */ | |
| 370 | + private static function should_send_email_to_active_campaign( $email ) { | |
| 371 | + $substrings = array( | |
| 372 | + '@wpengine.local', | |
| 373 | + '@example.com', | |
| 374 | + '@localhost', | |
| 375 | + '@local.dev', | |
| 376 | + '@local.test', | |
| 377 | + 'test@gmail.com', | |
| 378 | + 'admin@gmail.com', | |
| 379 | + | |
| 380 | + ); | |
| 381 | + foreach ( $substrings as $substring ) { | |
| 382 | + if ( false !== strpos( $email, $substring ) ) { | |
| 383 | + return false; | |
| 384 | + } | |
| 385 | + } | |
| 386 | + return true; | |
| 387 | + } | |
| 388 | + | |
| 389 | + /** | |
| 328 | 390 | * Handle AJAX request to set up usage data for the Onboarding Wizard. |
| 329 | 391 | * |
| 330 | 392 | * @since 6.9 |
| 331 | 393 | * |
| @@ -428,9 +490,8 @@ | ||
| 428 | 490 | * |
| 429 | 491 | * @since 6.9 |
| 430 | 492 | * |
| 431 | 493 | * @param string $classes Existing body classes. |
| 432 | - * | |
| 433 | 494 | * @return string Updated list of body classes, including the newly added classes. |
| 434 | 495 | */ |
| 435 | 496 | public static function add_admin_body_classes( $classes ) { |
| 436 | 497 | return $classes . ' frm-admin-full-screen'; |
| @@ -439,9 +500,8 @@ | ||
| 439 | 500 | /** |
| 440 | 501 | * Checks if the Onboarding Wizard was skipped during the plugin's installation. |
| 441 | 502 | * |
| 442 | 503 | * @since 6.9 |
| 443 | - * | |
| 444 | 504 | * @return bool True if the Onboarding Wizard was skipped, false otherwise. |
| 445 | 505 | */ |
| 446 | 506 | public static function has_onboarding_been_skipped() { |
| 447 | 507 | return get_option( self::ONBOARDING_SKIPPED_OPTION, false ); |
| @@ -450,13 +510,12 @@ | ||
| 450 | 510 | /** |
| 451 | 511 | * Marks the Onboarding Wizard as skipped to prevent automatic redirects to the wizard. |
| 452 | 512 | * |
| 453 | 513 | * @since 6.9 |
| 454 | - * | |
| 455 | 514 | * @return void |
| 456 | 515 | */ |
| 457 | 516 | public static function mark_onboarding_as_skipped() { |
| 458 | - update_option( self::ONBOARDING_SKIPPED_OPTION, true, false ); | |
| 517 | + update_option( self::ONBOARDING_SKIPPED_OPTION, true, 'no' ); | |
| 459 | 518 | } |
| 460 | 519 | |
| 461 | 520 | /** |
| 462 | 521 | * Adds an Onboarding Wizard welcome message to the floating notifications. |
| @@ -462,29 +521,24 @@ | ||
| 462 | 521 | * Adds an Onboarding Wizard welcome message to the floating notifications. |
| 463 | 522 | * |
| 464 | 523 | * @since 6.9 |
| 465 | 524 | * |
| 466 | - * @param mixed $inbox_messages The inbox option data. An array of existing inbox messages if there is valid data set in the option. | |
| 467 | - * | |
| 525 | + * @param array $inbox_messages The array of existing inbox messages. | |
| 468 | 526 | * @return array Configuration for the onboarding wizard slide-in notification. |
| 469 | 527 | */ |
| 470 | 528 | public static function add_wizard_to_floating_links( $inbox_messages ) { |
| 471 | - $message = __( 'Welcome to Formidable Forms! Click here to run the Onboarding Wizard and it will guide you through the basic settings and get you started in 2 minutes.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 529 | + $message = __( 'Welcome to Formidable Forms! Click here to run the Onboarding Wizard and it will guide you through the basic settings and get you started in 2 minutes.', 'formidable' ); | |
| 472 | 530 | |
| 473 | - if ( ! is_array( $inbox_messages ) ) { | |
| 474 | - $inbox_messages = array(); | |
| 475 | - } | |
| 476 | - | |
| 477 | - $inbox_messages['onboarding_wizard'] = array( | |
| 478 | - 'subject' => esc_html__( 'Begin With Ease!', 'formidable' ), | |
| 479 | - 'message' => esc_html( $message ), | |
| 480 | - 'slidein' => esc_html( $message ), | |
| 481 | - 'cta' => '<a href="' . esc_url( self::$page_url ) . '" class="button-primary frm-button-primary" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Begin Setup', 'formidable' ) . '</a>', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 482 | - 'created' => time(), | |
| 483 | - 'key' => 'onboarding_wizard', | |
| 531 | + return array( | |
| 532 | + 'onboarding_wizard' => array( | |
| 533 | + 'subject' => esc_html__( 'Begin With Ease!', 'formidable' ), | |
| 534 | + 'message' => esc_html( $message ), | |
| 535 | + 'slidein' => esc_html( $message ), | |
| 536 | + 'cta' => '<a href="' . esc_url( self::$page_url ) . '" class="button-primary frm-button-primary" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Begin Setup', 'formidable' ) . '</a>', | |
| 537 | + 'created' => time(), | |
| 538 | + 'key' => 'onboarding_wizard', | |
| 539 | + ), | |
| 484 | 540 | ); |
| 485 | - | |
| 486 | - return $inbox_messages; | |
| 487 | 541 | } |
| 488 | 542 | |
| 489 | 543 | /** |
| 490 | 544 | * Check if the current page is the Onboarding Wizard page. |
| @@ -506,9 +560,9 @@ | ||
| 506 | 560 | if ( get_option( self::REDIRECT_STATUS_OPTION ) ) { |
| 507 | 561 | return true; |
| 508 | 562 | } |
| 509 | 563 | |
| 510 | - update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), false ); | |
| 564 | + update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), 'no' ); | |
| 511 | 565 | return false; |
| 512 | 566 | } |
| 513 | 567 | |
| 514 | 568 | /** |
| @@ -640,41 +694,36 @@ | ||
| 640 | 694 | foreach ( $available_pro_addons as $key => $data ) { |
| 641 | 695 | $addon = FrmAddonsController::get_addon( $data['addon_key'] ); |
| 642 | 696 | $plugin_file = $data['plugin_file']; |
| 643 | 697 | |
| 644 | - if ( is_plugin_active( $plugin_file ) || ! isset( $addon['url'] ) ) { | |
| 645 | - continue; | |
| 698 | + if ( ! is_plugin_active( $plugin_file ) && isset( $addon['url'] ) ) { | |
| 699 | + $is_installed = array_key_exists( $plugin_file, $plugins ); | |
| 700 | + | |
| 701 | + self::$available_addons[ $key ] = array( | |
| 702 | + 'title' => $data['title'], | |
| 703 | + 'rel' => $is_installed ? $plugin_file : $addon['url'], | |
| 704 | + 'is-checked' => false, | |
| 705 | + 'is-installed' => $is_installed, | |
| 706 | + 'help-text' => $addon['excerpt'], | |
| 707 | + ); | |
| 646 | 708 | } |
| 647 | - | |
| 648 | - $is_installed = array_key_exists( $plugin_file, $plugins ); | |
| 649 | - | |
| 650 | - self::$available_addons[ $key ] = array( | |
| 651 | - 'title' => $data['title'], | |
| 652 | - 'rel' => $is_installed ? $plugin_file : $addon['url'], | |
| 653 | - 'is-checked' => false, | |
| 654 | - 'is-installed' => $is_installed, | |
| 655 | - 'help-text' => $addon['excerpt'], | |
| 656 | - ); | |
| 657 | 709 | } |
| 658 | 710 | }//end if |
| 659 | 711 | |
| 660 | 712 | // Gravity Forms Migrator add-on. |
| 661 | 713 | $gravity_forms_plugin = 'formidable-gravity-forms-importer/formidable-gravity-forms-importer.php'; |
| 714 | + if ( class_exists( 'GFForms' ) && ! is_plugin_active( $gravity_forms_plugin ) ) { | |
| 715 | + $is_installed_gravity_forms = array_key_exists( $gravity_forms_plugin, $plugins ); | |
| 662 | 716 | |
| 663 | - if ( ! class_exists( 'GFForms' ) || is_plugin_active( $gravity_forms_plugin ) ) { | |
| 664 | - return; | |
| 717 | + self::$available_addons['formidable-gravity-forms-importer'] = array( | |
| 718 | + 'title' => esc_html__( 'Gravity Forms Migrator', 'formidable' ), | |
| 719 | + 'rel' => $is_installed_gravity_forms ? $gravity_forms_plugin : 'formidable-gravity-forms-importer', | |
| 720 | + 'is-checked' => false, | |
| 721 | + 'is-vendor' => true, | |
| 722 | + 'is-installed' => $is_installed_gravity_forms, | |
| 723 | + 'help-text' => esc_html__( 'Easily migrate your forms from Gravity Forms to Formidable.', 'formidable' ), | |
| 724 | + ); | |
| 665 | 725 | } |
| 666 | - | |
| 667 | - $is_installed_gravity_forms = array_key_exists( $gravity_forms_plugin, $plugins ); | |
| 668 | - | |
| 669 | - self::$available_addons['formidable-gravity-forms-importer'] = array( | |
| 670 | - 'title' => esc_html__( 'Gravity Forms Migrator', 'formidable' ), | |
| 671 | - 'rel' => $is_installed_gravity_forms ? $gravity_forms_plugin : 'formidable-gravity-forms-importer', | |
| 672 | - 'is-checked' => false, | |
| 673 | - 'is-vendor' => true, | |
| 674 | - 'is-installed' => $is_installed_gravity_forms, | |
| 675 | - 'help-text' => esc_html__( 'Easily migrate your forms from Gravity Forms to Formidable.', 'formidable' ), | |
| 676 | - ); | |
| 677 | 726 | } |
| 678 | 727 | |
| 679 | 728 | /** |
| 680 | 729 | * Get the path to the Onboarding Wizard views. |