← All changes
|
classes/controllers/FrmOnboardingWizardController.php
+62
-47
6.26
→
trunk
View file →
| @@ -130,10 +130,15 @@ | ||
| 130 | 130 | if ( self::has_onboarding_been_skipped() ) { |
| 131 | 131 | add_filter( 'option_frm_inbox', self::class . '::add_wizard_to_floating_links' ); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - // Load page if admin page is Onboarding Wizard. | |
| 135 | - 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' ); | |
| 136 | 141 | } |
| 137 | 142 | |
| 138 | 143 | /** |
| 139 | 144 | * Performs a safe redirect to the welcome screen when the plugin is activated. |
| @@ -202,21 +207,23 @@ | ||
| 202 | 207 | * |
| 203 | 208 | * @return void |
| 204 | 209 | */ |
| 205 | 210 | public static function maybe_load_page() { |
| 206 | - if ( self::is_onboarding_wizard_page() ) { | |
| 207 | - // Dismiss the onboarding wizard message so it stops appearing after it is clicked. | |
| 208 | - $message = new FrmInbox(); | |
| 209 | - $message->dismiss( 'onboarding_wizard' ); | |
| 211 | + if ( ! self::is_onboarding_wizard_page() ) { | |
| 212 | + return; | |
| 213 | + } | |
| 210 | 214 | |
| 211 | - add_action( 'admin_menu', self::class . '::menu', 99 ); | |
| 212 | - add_action( 'admin_init', self::class . '::assign_properties' ); | |
| 213 | - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 ); | |
| 214 | - 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' ); | |
| 215 | 218 | |
| 216 | - add_filter( 'admin_body_class', self::class . '::add_admin_body_classes', 999 ); | |
| 217 | - add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 218 | - } | |
| 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' ); | |
| 219 | 226 | } |
| 220 | 227 | |
| 221 | 228 | /** |
| 222 | 229 | * Initializes class properties with essential values for operation. |
| @@ -452,9 +459,9 @@ | ||
| 452 | 459 | * |
| 453 | 460 | * @return void |
| 454 | 461 | */ |
| 455 | 462 | public static function mark_onboarding_as_skipped() { |
| 456 | - update_option( self::ONBOARDING_SKIPPED_OPTION, true, 'no' ); | |
| 463 | + update_option( self::ONBOARDING_SKIPPED_OPTION, true, false ); | |
| 457 | 464 | } |
| 458 | 465 | |
| 459 | 466 | /** |
| 460 | 467 | * Adds an Onboarding Wizard welcome message to the floating notifications. |
| @@ -460,25 +467,29 @@ | ||
| 460 | 467 | * Adds an Onboarding Wizard welcome message to the floating notifications. |
| 461 | 468 | * |
| 462 | 469 | * @since 6.9 |
| 463 | 470 | * |
| 464 | - * @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. | |
| 465 | 472 | * |
| 466 | 473 | * @return array Configuration for the onboarding wizard slide-in notification. |
| 467 | 474 | */ |
| 468 | 475 | public static function add_wizard_to_floating_links( $inbox_messages ) { |
| 469 | - $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 | |
| 470 | 477 | |
| 471 | - return array( | |
| 472 | - 'onboarding_wizard' => array( | |
| 473 | - 'subject' => esc_html__( 'Begin With Ease!', 'formidable' ), | |
| 474 | - 'message' => esc_html( $message ), | |
| 475 | - 'slidein' => esc_html( $message ), | |
| 476 | - '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>', | |
| 477 | - 'created' => time(), | |
| 478 | - 'key' => 'onboarding_wizard', | |
| 479 | - ), | |
| 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', | |
| 480 | 489 | ); |
| 490 | + | |
| 491 | + return $inbox_messages; | |
| 481 | 492 | } |
| 482 | 493 | |
| 483 | 494 | /** |
| 484 | 495 | * Check if the current page is the Onboarding Wizard page. |
| @@ -500,9 +511,9 @@ | ||
| 500 | 511 | if ( get_option( self::REDIRECT_STATUS_OPTION ) ) { |
| 501 | 512 | return true; |
| 502 | 513 | } |
| 503 | 514 | |
| 504 | - update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), 'no' ); | |
| 515 | + update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), false ); | |
| 505 | 516 | return false; |
| 506 | 517 | } |
| 507 | 518 | |
| 508 | 519 | /** |
| @@ -634,19 +645,21 @@ | ||
| 634 | 645 | foreach ( $available_pro_addons as $key => $data ) { |
| 635 | 646 | $addon = FrmAddonsController::get_addon( $data['addon_key'] ); |
| 636 | 647 | $plugin_file = $data['plugin_file']; |
| 637 | 648 | |
| 638 | - if ( ! is_plugin_active( $plugin_file ) && isset( $addon['url'] ) ) { | |
| 639 | - $is_installed = array_key_exists( $plugin_file, $plugins ); | |
| 649 | + if ( is_plugin_active( $plugin_file ) || ! isset( $addon['url'] ) ) { | |
| 650 | + continue; | |
| 651 | + } | |
| 640 | 652 | |
| 641 | - self::$available_addons[ $key ] = array( | |
| 642 | - 'title' => $data['title'], | |
| 643 | - 'rel' => $is_installed ? $plugin_file : $addon['url'], | |
| 644 | - 'is-checked' => false, | |
| 645 | - 'is-installed' => $is_installed, | |
| 646 | - 'help-text' => $addon['excerpt'], | |
| 647 | - ); | |
| 648 | - } | |
| 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 | + ); | |
| 649 | 662 | } |
| 650 | 663 | }//end if |
| 651 | 664 | |
| 652 | 665 | // Gravity Forms Migrator add-on. |
| @@ -651,20 +664,22 @@ | ||
| 651 | 664 | |
| 652 | 665 | // Gravity Forms Migrator add-on. |
| 653 | 666 | $gravity_forms_plugin = 'formidable-gravity-forms-importer/formidable-gravity-forms-importer.php'; |
| 654 | 667 | |
| 655 | - if ( class_exists( 'GFForms' ) && ! is_plugin_active( $gravity_forms_plugin ) ) { | |
| 656 | - $is_installed_gravity_forms = array_key_exists( $gravity_forms_plugin, $plugins ); | |
| 668 | + if ( ! class_exists( 'GFForms' ) || is_plugin_active( $gravity_forms_plugin ) ) { | |
| 669 | + return; | |
| 670 | + } | |
| 657 | 671 | |
| 658 | - self::$available_addons['formidable-gravity-forms-importer'] = array( | |
| 659 | - 'title' => esc_html__( 'Gravity Forms Migrator', 'formidable' ), | |
| 660 | - 'rel' => $is_installed_gravity_forms ? $gravity_forms_plugin : 'formidable-gravity-forms-importer', | |
| 661 | - 'is-checked' => false, | |
| 662 | - 'is-vendor' => true, | |
| 663 | - 'is-installed' => $is_installed_gravity_forms, | |
| 664 | - 'help-text' => esc_html__( 'Easily migrate your forms from Gravity Forms to Formidable.', 'formidable' ), | |
| 665 | - ); | |
| 666 | - } | |
| 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 | + ); | |
| 667 | 682 | } |
| 668 | 683 | |
| 669 | 684 | /** |
| 670 | 685 | * Get the path to the Onboarding Wizard views. |