← All changes
|
classes/controllers/FrmOnboardingWizardController.php
+70
-47
6.25
→
trunk
View file →
| @@ -119,8 +119,10 @@ | ||
| 119 | 119 | /** |
| 120 | 120 | * Initialize hooks for template page only. |
| 121 | 121 | * |
| 122 | 122 | * @since 6.9 |
| 123 | + * | |
| 124 | + * @return void | |
| 123 | 125 | */ |
| 124 | 126 | public static function load_admin_hooks() { |
| 125 | 127 | self::set_page_url(); |
| 126 | 128 | add_action( 'admin_init', self::class . '::do_admin_redirects' ); |
| @@ -128,10 +130,15 @@ | ||
| 128 | 130 | if ( self::has_onboarding_been_skipped() ) { |
| 129 | 131 | add_filter( 'option_frm_inbox', self::class . '::add_wizard_to_floating_links' ); |
| 130 | 132 | } |
| 131 | 133 | |
| 132 | - // Load page if admin page is Onboarding Wizard. | |
| 133 | - self::maybe_load_page(); | |
| 134 | + /** | |
| 135 | + * Load page if admin page is Onboarding Wizard. | |
| 136 | + * This waits for init because it reads the inbox option, and the filter above translates | |
| 137 | + * when it does. Translating before the text domain is loaded triggers a | |
| 138 | + * _load_textdomain_just_in_time notice in WordPress 6.7+. | |
| 139 | + */ | |
| 140 | + add_action( 'init', self::class . '::maybe_load_page' ); | |
| 134 | 141 | } |
| 135 | 142 | |
| 136 | 143 | /** |
| 137 | 144 | * Performs a safe redirect to the welcome screen when the plugin is activated. |
| @@ -158,8 +165,9 @@ | ||
| 158 | 165 | return; |
| 159 | 166 | } |
| 160 | 167 | |
| 161 | 168 | $transient_value = get_transient( self::TRANSIENT_NAME ); |
| 169 | + | |
| 162 | 170 | if ( ! in_array( $transient_value, array( self::TRANSIENT_VALUE, self::TRANSIENT_MULTI_VALUE ), true ) ) { |
| 163 | 171 | return; |
| 164 | 172 | } |
| 165 | 173 | |
| @@ -185,8 +193,9 @@ | ||
| 185 | 193 | } |
| 186 | 194 | |
| 187 | 195 | // Redirect to the onboarding wizard's initial step. |
| 188 | 196 | $page_url = add_query_arg( 'step', self::INITIAL_STEP, self::$page_url ); |
| 197 | + | |
| 189 | 198 | if ( wp_safe_redirect( esc_url_raw( $page_url ) ) ) { |
| 190 | 199 | exit; |
| 191 | 200 | } |
| 192 | 201 | } |
| @@ -198,21 +207,23 @@ | ||
| 198 | 207 | * |
| 199 | 208 | * @return void |
| 200 | 209 | */ |
| 201 | 210 | public static function maybe_load_page() { |
| 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' ); | |
| 211 | + if ( ! self::is_onboarding_wizard_page() ) { | |
| 212 | + return; | |
| 213 | + } | |
| 206 | 214 | |
| 207 | - add_action( 'admin_menu', self::class . '::menu', 99 ); | |
| 208 | - add_action( 'admin_init', self::class . '::assign_properties' ); | |
| 209 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 210 | - add_action( 'admin_head', self::class . '::remove_menu' ); | |
| 215 | + // Dismiss the onboarding wizard message so it stops appearing after it is clicked. | |
| 216 | + $message = new FrmInbox(); | |
| 217 | + $message->dismiss( 'onboarding_wizard' ); | |
| 211 | 218 | |
| 212 | - add_filter( 'admin_body_class', self::class . '::add_admin_body_classes', 999 ); | |
| 213 | - add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 214 | - } | |
| 219 | + add_action( 'admin_menu', self::class . '::menu', 99 ); | |
| 220 | + add_action( 'admin_init', self::class . '::assign_properties' ); | |
| 221 | + add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 222 | + add_action( 'admin_head', self::class . '::remove_menu' ); | |
| 223 | + | |
| 224 | + add_filter( 'admin_body_class', self::class . '::add_admin_body_classes', 999 ); | |
| 225 | + add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 215 | 226 | } |
| 216 | 227 | |
| 217 | 228 | /** |
| 218 | 229 | * Initializes class properties with essential values for operation. |
| @@ -317,9 +328,8 @@ | ||
| 317 | 328 | // Send response. |
| 318 | 329 | wp_send_json_success(); |
| 319 | 330 | } |
| 320 | 331 | |
| 321 | - | |
| 322 | 332 | /** |
| 323 | 333 | * Handle AJAX request to set up usage data for the Onboarding Wizard. |
| 324 | 334 | * |
| 325 | 335 | * @since 6.9 |
| @@ -423,8 +433,9 @@ | ||
| 423 | 433 | * |
| 424 | 434 | * @since 6.9 |
| 425 | 435 | * |
| 426 | 436 | * @param string $classes Existing body classes. |
| 437 | + * | |
| 427 | 438 | * @return string Updated list of body classes, including the newly added classes. |
| 428 | 439 | */ |
| 429 | 440 | public static function add_admin_body_classes( $classes ) { |
| 430 | 441 | return $classes . ' frm-admin-full-screen'; |
| @@ -433,8 +444,9 @@ | ||
| 433 | 444 | /** |
| 434 | 445 | * Checks if the Onboarding Wizard was skipped during the plugin's installation. |
| 435 | 446 | * |
| 436 | 447 | * @since 6.9 |
| 448 | + * | |
| 437 | 449 | * @return bool True if the Onboarding Wizard was skipped, false otherwise. |
| 438 | 450 | */ |
| 439 | 451 | public static function has_onboarding_been_skipped() { |
| 440 | 452 | return get_option( self::ONBOARDING_SKIPPED_OPTION, false ); |
| @@ -443,12 +455,13 @@ | ||
| 443 | 455 | /** |
| 444 | 456 | * Marks the Onboarding Wizard as skipped to prevent automatic redirects to the wizard. |
| 445 | 457 | * |
| 446 | 458 | * @since 6.9 |
| 459 | + * | |
| 447 | 460 | * @return void |
| 448 | 461 | */ |
| 449 | 462 | public static function mark_onboarding_as_skipped() { |
| 450 | - update_option( self::ONBOARDING_SKIPPED_OPTION, true, 'no' ); | |
| 463 | + update_option( self::ONBOARDING_SKIPPED_OPTION, true, false ); | |
| 451 | 464 | } |
| 452 | 465 | |
| 453 | 466 | /** |
| 454 | 467 | * Adds an Onboarding Wizard welcome message to the floating notifications. |
| @@ -454,24 +467,29 @@ | ||
| 454 | 467 | * Adds an Onboarding Wizard welcome message to the floating notifications. |
| 455 | 468 | * |
| 456 | 469 | * @since 6.9 |
| 457 | 470 | * |
| 458 | - * @param array $inbox_messages The array of existing inbox messages. | |
| 471 | + * @param mixed $inbox_messages The inbox option data. An array of existing inbox messages if there is valid data set in the option. | |
| 472 | + * | |
| 459 | 473 | * @return array Configuration for the onboarding wizard slide-in notification. |
| 460 | 474 | */ |
| 461 | 475 | public static function add_wizard_to_floating_links( $inbox_messages ) { |
| 462 | - $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' ); | |
| 476 | + $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 | |
| 463 | 477 | |
| 464 | - return array( | |
| 465 | - 'onboarding_wizard' => array( | |
| 466 | - 'subject' => esc_html__( 'Begin With Ease!', 'formidable' ), | |
| 467 | - 'message' => esc_html( $message ), | |
| 468 | - 'slidein' => esc_html( $message ), | |
| 469 | - '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>', | |
| 470 | - 'created' => time(), | |
| 471 | - 'key' => 'onboarding_wizard', | |
| 472 | - ), | |
| 478 | + if ( ! is_array( $inbox_messages ) ) { | |
| 479 | + $inbox_messages = array(); | |
| 480 | + } | |
| 481 | + | |
| 482 | + $inbox_messages['onboarding_wizard'] = array( | |
| 483 | + 'subject' => esc_html__( 'Begin With Ease!', 'formidable' ), | |
| 484 | + 'message' => esc_html( $message ), | |
| 485 | + 'slidein' => esc_html( $message ), | |
| 486 | + '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 | |
| 487 | + 'created' => time(), | |
| 488 | + 'key' => 'onboarding_wizard', | |
| 473 | 489 | ); |
| 490 | + | |
| 491 | + return $inbox_messages; | |
| 474 | 492 | } |
| 475 | 493 | |
| 476 | 494 | /** |
| 477 | 495 | * Check if the current page is the Onboarding Wizard page. |
| @@ -493,9 +511,9 @@ | ||
| 493 | 511 | if ( get_option( self::REDIRECT_STATUS_OPTION ) ) { |
| 494 | 512 | return true; |
| 495 | 513 | } |
| 496 | 514 | |
| 497 | - update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), 'no' ); | |
| 515 | + update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), false ); | |
| 498 | 516 | return false; |
| 499 | 517 | } |
| 500 | 518 | |
| 501 | 519 | /** |
| @@ -627,36 +645,41 @@ | ||
| 627 | 645 | foreach ( $available_pro_addons as $key => $data ) { |
| 628 | 646 | $addon = FrmAddonsController::get_addon( $data['addon_key'] ); |
| 629 | 647 | $plugin_file = $data['plugin_file']; |
| 630 | 648 | |
| 631 | - if ( ! is_plugin_active( $plugin_file ) && isset( $addon['url'] ) ) { | |
| 632 | - $is_installed = array_key_exists( $plugin_file, $plugins ); | |
| 649 | + if ( is_plugin_active( $plugin_file ) || ! isset( $addon['url'] ) ) { | |
| 650 | + continue; | |
| 651 | + } | |
| 633 | 652 | |
| 634 | - self::$available_addons[ $key ] = array( | |
| 635 | - 'title' => $data['title'], | |
| 636 | - 'rel' => $is_installed ? $plugin_file : $addon['url'], | |
| 637 | - 'is-checked' => false, | |
| 638 | - 'is-installed' => $is_installed, | |
| 639 | - 'help-text' => $addon['excerpt'], | |
| 640 | - ); | |
| 641 | - } | |
| 653 | + $is_installed = array_key_exists( $plugin_file, $plugins ); | |
| 654 | + | |
| 655 | + self::$available_addons[ $key ] = array( | |
| 656 | + 'title' => $data['title'], | |
| 657 | + 'rel' => $is_installed ? $plugin_file : $addon['url'], | |
| 658 | + 'is-checked' => false, | |
| 659 | + 'is-installed' => $is_installed, | |
| 660 | + 'help-text' => $addon['excerpt'], | |
| 661 | + ); | |
| 642 | 662 | } |
| 643 | 663 | }//end if |
| 644 | 664 | |
| 645 | 665 | // Gravity Forms Migrator add-on. |
| 646 | 666 | $gravity_forms_plugin = 'formidable-gravity-forms-importer/formidable-gravity-forms-importer.php'; |
| 647 | - if ( class_exists( 'GFForms' ) && ! is_plugin_active( $gravity_forms_plugin ) ) { | |
| 648 | - $is_installed_gravity_forms = array_key_exists( $gravity_forms_plugin, $plugins ); | |
| 649 | 667 | |
| 650 | - self::$available_addons['formidable-gravity-forms-importer'] = array( | |
| 651 | - 'title' => esc_html__( 'Gravity Forms Migrator', 'formidable' ), | |
| 652 | - 'rel' => $is_installed_gravity_forms ? $gravity_forms_plugin : 'formidable-gravity-forms-importer', | |
| 653 | - 'is-checked' => false, | |
| 654 | - 'is-vendor' => true, | |
| 655 | - 'is-installed' => $is_installed_gravity_forms, | |
| 656 | - 'help-text' => esc_html__( 'Easily migrate your forms from Gravity Forms to Formidable.', 'formidable' ), | |
| 657 | - ); | |
| 668 | + if ( ! class_exists( 'GFForms' ) || is_plugin_active( $gravity_forms_plugin ) ) { | |
| 669 | + return; | |
| 658 | 670 | } |
| 671 | + | |
| 672 | + $is_installed_gravity_forms = array_key_exists( $gravity_forms_plugin, $plugins ); | |
| 673 | + | |
| 674 | + self::$available_addons['formidable-gravity-forms-importer'] = array( | |
| 675 | + 'title' => esc_html__( 'Gravity Forms Migrator', 'formidable' ), | |
| 676 | + 'rel' => $is_installed_gravity_forms ? $gravity_forms_plugin : 'formidable-gravity-forms-importer', | |
| 677 | + 'is-checked' => false, | |
| 678 | + 'is-vendor' => true, | |
| 679 | + 'is-installed' => $is_installed_gravity_forms, | |
| 680 | + 'help-text' => esc_html__( 'Easily migrate your forms from Gravity Forms to Formidable.', 'formidable' ), | |
| 681 | + ); | |
| 659 | 682 | } |
| 660 | 683 | |
| 661 | 684 | /** |
| 662 | 685 | * Get the path to the Onboarding Wizard views. |