booking
/
includes
/
page-setup-wizard
/
first-run-launcher
/
class-wpbc-setup-wizard-first-install-activation.php
class-wpbc-setup-wizard-first-install-activation.php in Booking Calendar 11.9, at includes/page-setup-wizard/first-run-launcher/class-wpbc-setup-wizard-first-install-activation.php
| 1 | <?php |
| 2 | /** |
| 3 | * Genuine first-install activation integration for Setup Wizard. |
| 4 | * |
| 5 | * @package Booking Calendar |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Route a genuine first installation directly to the Setup Wizard. |
| 14 | * |
| 15 | * Update and reactivation intents are intentionally ignored here so the released |
| 16 | * Welcome controller can continue opening What's New. Legacy boolean transients |
| 17 | * are also left to that compatibility path. |
| 18 | */ |
| 19 | final class WPBC_Setup_Wizard_First_Install_Activation { |
| 20 | |
| 21 | /** Legacy Free redirect transient shared with the released Welcome controller. */ |
| 22 | const LEGACY_REDIRECT_TRANSIENT = '_booking_activation_redirect'; |
| 23 | |
| 24 | /** Legacy paid redirect transient written by older Pro activation callbacks. */ |
| 25 | const LEGACY_PRO_REDIRECT_TRANSIENT = '_booking_pro_activation_redirect'; |
| 26 | |
| 27 | /** |
| 28 | * Register the first-install redirect before the released What's New handler. |
| 29 | * |
| 30 | * @return void |
| 31 | */ |
| 32 | public static function register() { |
| 33 | add_action( 'admin_init', array( __CLASS__, 'maybe_redirect_to_setup_wizard' ), 5 ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Consume a genuine-install intent and open the canonical Setup Wizard. |
| 38 | * |
| 39 | * Starting automatically is equivalent to choosing Start guided setup from |
| 40 | * the fallback invitation: the invitation is consumed, while no checkpoint |
| 41 | * or canonical setting is created until the first successful wizard save. |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | public static function maybe_redirect_to_setup_wizard() { |
| 46 | if ( 'On' === get_bk_option( 'booking_activation_process' ) ) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | if ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | $redirect_intent = get_transient( WPBC_Setup_Wizard_First_Install_State::ACTIVATION_INTENT_TRANSIENT ); |
| 55 | if ( ! WPBC_Setup_Wizard_First_Install_State::is_first_install_redirect_intent( $redirect_intent ) ) { |
| 56 | return; |
| 57 | } |
| 58 | if ( ! WPBC_Setup_Wizard_First_Install_State::is_redirect_intent_for_current_user( $redirect_intent ) ) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if ( WPBC_Setup_Wizard_First_Install_State::is_automatic_onboarding_restricted() ) { |
| 63 | delete_transient( WPBC_Setup_Wizard_First_Install_State::ACTIVATION_INTENT_TRANSIENT ); |
| 64 | delete_transient( self::LEGACY_REDIRECT_TRANSIENT ); |
| 65 | delete_transient( self::LEGACY_PRO_REDIRECT_TRANSIENT ); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | if ( ! WPBC_Setup_Wizard_Access::current_user_can_access() ) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | delete_transient( WPBC_Setup_Wizard_First_Install_State::ACTIVATION_INTENT_TRANSIENT ); |
| 74 | delete_transient( self::LEGACY_REDIRECT_TRANSIENT ); |
| 75 | delete_transient( self::LEGACY_PRO_REDIRECT_TRANSIENT ); |
| 76 | |
| 77 | $redirect_for_version = get_bk_option( 'booking_activation_redirect_for_version' ); |
| 78 | if ( WP_BK_VERSION_NUM === $redirect_for_version ) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | update_bk_option( 'booking_activation_redirect_for_version', WP_BK_VERSION_NUM ); |
| 83 | update_bk_option( 'booking_setup_wizard_first_run_prompt', 'Off' ); |
| 84 | |
| 85 | wp_safe_redirect( wpbc_get_setup_wizard_page_url() ); |
| 86 | exit; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Compatibility alias for the earlier 11.9 development callback name. |
| 91 | * |
| 92 | * @deprecated 11.9 Use maybe_redirect_to_setup_wizard(). |
| 93 | * |
| 94 | * @return void |
| 95 | */ |
| 96 | public static function maybe_redirect_to_booking_listing() { |
| 97 | self::maybe_redirect_to_setup_wizard(); |
| 98 | } |
| 99 | } |
| 100 |