| 1 |
<?php |
| 2 |
/** |
| 3 |
* Production bootstrap for the Booking Calendar Setup Wizard. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! is_admin() ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
require_once __DIR__ . '/class-wpbc-setup-wizard-access.php'; |
| 17 |
require_once __DIR__ . '/class-wpbc-setup-wizard-environment-policy.php'; |
| 18 |
require_once __DIR__ . '/first-run-launcher/class-wpbc-setup-wizard-first-install-state.php'; |
| 19 |
require_once __DIR__ . '/first-run-launcher/class-wpbc-setup-wizard-first-install-activation.php'; |
| 20 |
require_once __DIR__ . '/interface-wpbc-setup-wizard-step-module.php'; |
| 21 |
require_once __DIR__ . '/class-wpbc-setup-wizard-customer-journey-policy.php'; |
| 22 |
require_once __DIR__ . '/step-date-time-formats/class-wpbc-setup-wizard-date-time-formats.php'; |
| 23 |
require_once __DIR__ . '/step-date-time-formats/class-wpbc-setup-wizard-date-time-formats-ajax.php'; |
| 24 |
require_once __DIR__ . '/step-date-time-formats/class-wpbc-setup-wizard-date-time-formats-module.php'; |
| 25 |
require_once __DIR__ . '/step-date-selection/class-wpbc-setup-wizard-date-selection.php'; |
| 26 |
require_once __DIR__ . '/step-date-selection/class-wpbc-setup-wizard-date-selection-module.php'; |
| 27 |
require_once __DIR__ . '/step-days-off/class-wpbc-setup-wizard-days-off.php'; |
| 28 |
require_once __DIR__ . '/step-days-off/class-wpbc-setup-wizard-days-off-ajax.php'; |
| 29 |
require_once __DIR__ . '/step-days-off/class-wpbc-setup-wizard-days-off-module.php'; |
| 30 |
require_once __DIR__ . '/step-services/class-wpbc-setup-wizard-services.php'; |
| 31 |
require_once __DIR__ . '/step-services/class-wpbc-setup-wizard-services-module.php'; |
| 32 |
require_once __DIR__ . '/step-booking-resources/class-wpbc-setup-wizard-booking-resources.php'; |
| 33 |
require_once __DIR__ . '/step-booking-resources/class-wpbc-setup-wizard-booking-resources-module.php'; |
| 34 |
require_once __DIR__ . '/step-start-end-times/class-wpbc-setup-wizard-start-end-times.php'; |
| 35 |
require_once __DIR__ . '/step-start-end-times/class-wpbc-setup-wizard-start-end-times-module.php'; |
| 36 |
require_once __DIR__ . '/step-start-duration-times/class-wpbc-setup-wizard-start-duration-times.php'; |
| 37 |
require_once __DIR__ . '/step-start-duration-times/class-wpbc-setup-wizard-start-duration-times-module.php'; |
| 38 |
require_once __DIR__ . '/step-fixed-time-slots/class-wpbc-setup-wizard-fixed-time-slots.php'; |
| 39 |
require_once __DIR__ . '/step-fixed-time-slots/class-wpbc-setup-wizard-fixed-time-slots-module.php'; |
| 40 |
require_once __DIR__ . '/step-working-hours/class-wpbc-setup-wizard-working-hours.php'; |
| 41 |
require_once __DIR__ . '/step-working-hours/class-wpbc-setup-wizard-working-hours-module.php'; |
| 42 |
require_once __DIR__ . '/step-booking-form-template/class-wpbc-setup-wizard-booking-form-templates.php'; |
| 43 |
require_once __DIR__ . '/step-booking-form-template/class-wpbc-setup-wizard-booking-form-time-options.php'; |
| 44 |
require_once __DIR__ . '/step-booking-form-template/class-wpbc-setup-wizard-booking-form-preview.php'; |
| 45 |
require_once __DIR__ . '/step-booking-form-template/class-wpbc-setup-wizard-booking-form-preview-ajax.php'; |
| 46 |
require_once __DIR__ . '/step-booking-form-template/class-wpbc-setup-wizard-booking-form-template-module.php'; |
| 47 |
require_once __DIR__ . '/step-appearance/class-wpbc-setup-wizard-appearance.php'; |
| 48 |
require_once __DIR__ . '/step-appearance/class-wpbc-setup-wizard-appearance-module.php'; |
| 49 |
require_once __DIR__ . '/step-publish-integration/class-wpbc-setup-wizard-publish-integration.php'; |
| 50 |
require_once __DIR__ . '/step-publish-integration/class-wpbc-setup-wizard-publish-integration-module.php'; |
| 51 |
require_once __DIR__ . '/step-review-setup/class-wpbc-setup-wizard-review-setup.php'; |
| 52 |
require_once __DIR__ . '/step-review-setup/class-wpbc-setup-wizard-review-setup-module.php'; |
| 53 |
require_once __DIR__ . '/class-wpbc-setup-wizard-step-module-registry.php'; |
| 54 |
require_once __DIR__ . '/class-wpbc-setup-wizard-step-registry.php'; |
| 55 |
require_once __DIR__ . '/class-wpbc-setup-wizard-settings-hints.php'; |
| 56 |
require_once __DIR__ . '/class-wpbc-setup-wizard-templates.php'; |
| 57 |
require_once __DIR__ . '/class-wpbc-setup-wizard-step-data.php'; |
| 58 |
require_once __DIR__ . '/class-wpbc-setup-wizard-draft-validator.php'; |
| 59 |
require_once __DIR__ . '/interface-wpbc-setup-wizard-checkpoint-store.php'; |
| 60 |
require_once __DIR__ . '/interface-wpbc-setup-wizard-email-state-store.php'; |
| 61 |
require_once __DIR__ . '/interface-wpbc-setup-wizard-step-save-handler.php'; |
| 62 |
require_once __DIR__ . '/class-wpbc-setup-wizard-step-save-registry.php'; |
| 63 |
require_once __DIR__ . '/class-wpbc-setup-wizard-checkpoint-only-save-handler.php'; |
| 64 |
require_once __DIR__ . '/class-wpbc-setup-wizard-metadata-save-handler.php'; |
| 65 |
require_once __DIR__ . '/class-wpbc-setup-wizard-customer-journey-save-handler.php'; |
| 66 |
require_once __DIR__ . '/step-date-time-formats/class-wpbc-setup-wizard-date-time-formats-save-handler.php'; |
| 67 |
require_once __DIR__ . '/class-wpbc-setup-wizard-booking-mode-save-handler.php'; |
| 68 |
require_once __DIR__ . '/step-date-selection/class-wpbc-setup-wizard-date-selection-save-handler.php'; |
| 69 |
require_once __DIR__ . '/step-services/class-wpbc-setup-wizard-services-save-handler.php'; |
| 70 |
require_once __DIR__ . '/step-booking-resources/class-wpbc-setup-wizard-booking-resources-save-handler.php'; |
| 71 |
require_once __DIR__ . '/step-start-end-times/class-wpbc-setup-wizard-start-end-times-save-handler.php'; |
| 72 |
require_once __DIR__ . '/step-start-duration-times/class-wpbc-setup-wizard-start-duration-times-save-handler.php'; |
| 73 |
require_once __DIR__ . '/step-fixed-time-slots/class-wpbc-setup-wizard-fixed-time-slots-save-handler.php'; |
| 74 |
require_once __DIR__ . '/step-working-hours/class-wpbc-setup-wizard-working-hours-save-handler.php'; |
| 75 |
require_once __DIR__ . '/step-days-off/class-wpbc-setup-wizard-days-off-save-handler.php'; |
| 76 |
require_once __DIR__ . '/step-booking-form-template/class-wpbc-setup-wizard-booking-form-template-save-handler.php'; |
| 77 |
require_once __DIR__ . '/step-appearance/class-wpbc-setup-wizard-appearance-save-handler.php'; |
| 78 |
require_once __DIR__ . '/step-publish-integration/class-wpbc-setup-wizard-publish-integration-save-handler.php'; |
| 79 |
require_once __DIR__ . '/class-wpbc-setup-wizard-operation-lock.php'; |
| 80 |
require_once __DIR__ . '/class-wpbc-setup-wizard-draft-store.php'; |
| 81 |
require_once __DIR__ . '/booking-pages/class-wpbc-setup-wizard-booking-pages.php'; |
| 82 |
require_once __DIR__ . '/first-run-launcher/class-wpbc-setup-wizard-first-run-launcher.php'; |
| 83 |
require_once __DIR__ . '/step-review-setup/class-wpbc-setup-wizard-summary-email.php'; |
| 84 |
require_once __DIR__ . '/class-wpbc-setup-wizard-progressive-save-coordinator.php'; |
| 85 |
require_once __DIR__ . '/class-wpbc-setup-wizard-progressive-save-factory.php'; |
| 86 |
require_once __DIR__ . '/ajax/class-wpbc-setup-wizard-ajax.php'; |
| 87 |
require_once __DIR__ . '/setup-overview/class-wpbc-setup-wizard-setup-overview.php'; |
| 88 |
require_once __DIR__ . '/setup-overview/class-wpbc-setup-wizard-setup-overview-actions.php'; |
| 89 |
require_once __DIR__ . '/class-wpbc-setup-wizard-page.php'; |
| 90 |
WPBC_Setup_Wizard_Ajax::register(); |
| 91 |
WPBC_Setup_Wizard_Date_Time_Formats_Ajax::register(); |
| 92 |
WPBC_Setup_Wizard_Days_Off_Ajax::register(); |
| 93 |
WPBC_Setup_Wizard_Booking_Form_Preview_Ajax::register(); |
| 94 |
WPBC_Setup_Wizard_Setup_Overview_Actions::register(); |
| 95 |
WPBC_Setup_Wizard_Booking_Pages::register(); |
| 96 |
WPBC_Setup_Wizard_First_Run_Launcher::register(); |
| 97 |
WPBC_Setup_Wizard_First_Install_Activation::register(); |
| 98 |
add_action( 'admin_init', 'wpbc_setup_wizard_redirect_legacy_settings_action', 1 ); |
| 99 |
add_action( '_admin_menu', 'wpbc_setup_wizard_register_menu_controller', 20 ); |
| 100 |
add_action( 'wpbc_menu_created', 'wpbc_setup_wizard_attach_page_controller', 10, 1 ); |
| 101 |
|
| 102 |
/** |
| 103 |
* Redirect the released Settings reset bookmark to the canonical Setup Wizard. |
| 104 |
* |
| 105 |
* Older links used the Settings renderer as an intermediate redirect. Keeping |
| 106 |
* that compatibility at the Setup Wizard routing boundary prevents ordinary |
| 107 |
* Settings requests from inspecting or acting on wizard parameters. |
| 108 |
* |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
function wpbc_setup_wizard_redirect_legacy_settings_action() { |
| 112 |
global $pagenow; |
| 113 |
|
| 114 |
if ( wp_doing_ajax() || 'admin.php' !== $pagenow ) { |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only administration routing compatibility. |
| 119 |
$page_slug = isset( $_GET['page'] ) && is_scalar( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; |
| 120 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only administration routing compatibility. |
| 121 |
$compatibility_action = isset( $_GET['wpbc_setup_wizard'] ) && is_scalar( $_GET['wpbc_setup_wizard'] ) |
| 122 |
? sanitize_key( wp_unslash( $_GET['wpbc_setup_wizard'] ) ) |
| 123 |
: ''; |
| 124 |
|
| 125 |
if ( 'wpbc-settings' !== $page_slug || 'reset' !== $compatibility_action ) { |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
if ( ! WPBC_Setup_Wizard_Access::current_user_can_access() ) { |
| 130 |
wp_die( |
| 131 |
esc_html__( 'You are not allowed to use this Setup Wizard.', 'booking' ), |
| 132 |
esc_html__( 'Access denied', 'booking' ), |
| 133 |
array( 'response' => 403 ) |
| 134 |
); |
| 135 |
} |
| 136 |
|
| 137 |
wp_safe_redirect( wpbc_get_setup_wizard_page_url() ); |
| 138 |
exit; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Register the canonical menu through the native Booking Calendar menu system. |
| 143 |
* |
| 144 |
* The object is retained for the request because its WordPress callbacks are |
| 145 |
* instance methods. A stable title replaces the legacy progress-title |
| 146 |
* generator, and the same entry remains available before and after completion. |
| 147 |
* |
| 148 |
* @return void |
| 149 |
*/ |
| 150 |
function wpbc_setup_wizard_register_menu_controller() { |
| 151 |
static $menu_controller = null; |
| 152 |
|
| 153 |
if ( |
| 154 |
null !== $menu_controller |
| 155 |
|| ! class_exists( 'WPBC_Admin_Menus' ) |
| 156 |
|| ! WPBC_Setup_Wizard_Access::current_user_can_access() |
| 157 |
) { |
| 158 |
return; |
| 159 |
} |
| 160 |
|
| 161 |
$menu_controller = new WPBC_Admin_Menus( |
| 162 |
'wpbc-setup', |
| 163 |
array( |
| 164 |
'in_menu' => 'wpbc', |
| 165 |
'menu_title' => __( 'Setup Wizard', 'booking' ), |
| 166 |
'page_header' => __( 'Setup Wizard', 'booking' ), |
| 167 |
'browser_header' => __( 'Setup Wizard', 'booking' ) . ' - ' . __( 'Booking Calendar', 'booking' ), |
| 168 |
'user_role' => get_bk_option( 'booking_user_role_settings' ), |
| 169 |
) |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Attach the page structure after the matching native menu has been created. |
| 175 |
* |
| 176 |
* @param string $menu_tag Booking Calendar menu slug that was just created. |
| 177 |
* |
| 178 |
* @return void |
| 179 |
*/ |
| 180 |
function wpbc_setup_wizard_attach_page_controller( $menu_tag ) { |
| 181 |
static $page_controller = null; |
| 182 |
|
| 183 |
if ( 'wpbc-setup' !== $menu_tag || null !== $page_controller ) { |
| 184 |
return; |
| 185 |
} |
| 186 |
|
| 187 |
$page_controller = new WPBC_Setup_Wizard_Page(); |
| 188 |
} |
| 189 |
|