| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php /** |
| 2 | 2 | * @version 1.0 |
| 3 | 3 | * @description Support functions for the Setup Wizard Page |
| 4 | 4 | * @category Setup Class |
| @@ -9,13 +9,29 @@ | ||
| 9 | 9 | * |
| 10 | 10 | * @modified 2024-09-06 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 14 | - | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * Do we need to start 'Setup Wizard' ? | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 14 | + | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * Check whether this site was initialized by the current first-install flow. | |
| 18 | + * | |
| 19 | + * This persisted marker is intentionally separate from wizard completion and | |
| 20 | + * prompt dismissal. It prevents plugin updates from adding the native Setup menu | |
| 21 | + * while allowing a new administrator to postpone the popup and return through | |
| 22 | + * that menu later. | |
| 23 | + * | |
| 24 | + * @return bool True for sites marked during genuine first installation. | |
| 25 | + */ | |
| 26 | +function wpbc_setup_wizard_is_initial_install_site() { | |
| 27 | + | |
| 28 | + return 'On' === get_bk_option( 'booking_setup_wizard_initial_install' ); | |
| 29 | +} | |
| 30 | + | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Do we need to start 'Setup Wizard' ? | |
| 18 | 34 | * |
| 19 | 35 | * @return bool |
| 20 | 36 | */ |
| 21 | 37 | function wpbc_setup_wizard_page__is_need_start(){ |
| @@ -46,16 +62,119 @@ | ||
| 46 | 62 | * Do we need to Continue 'Setup Wizard' or all steps already completed ? |
| 47 | 63 | * |
| 48 | 64 | * @return bool |
| 49 | 65 | */ |
| 50 | -function wpbc_setup_wizard_page__is_all_steps_completed() { | |
| 66 | +function wpbc_setup_wizard_page__is_all_steps_completed() { | |
| 51 | 67 | |
| 52 | 68 | $setup_steps = new WPBC_SETUP_WIZARD_STEPS(); |
| 53 | 69 | |
| 54 | 70 | $is_all_steps_completed = $setup_steps->db__is_all_steps_completed(); |
| 55 | 71 | |
| 56 | - return $is_all_steps_completed; | |
| 57 | -} | |
| 72 | + return $is_all_steps_completed; | |
| 73 | +} | |
| 74 | + | |
| 75 | + | |
| 76 | +/** | |
| 77 | + * Check whether the Setup Wizard has started and is not yet complete. | |
| 78 | + * | |
| 79 | + * Explicit Setup Wizard requests count as active before the first step has | |
| 80 | + * been saved. Persisted completed steps keep the wizard active while the user | |
| 81 | + * visits another Booking Calendar administration page. A completed or skipped | |
| 82 | + * wizard is not considered in progress. | |
| 83 | + * | |
| 84 | + * @return bool True while an unfinished Setup Wizard is in progress. | |
| 85 | + */ | |
| 86 | +function wpbc_setup_wizard_page__is_in_progress() { | |
| 87 | + | |
| 88 | + if ( wpbc_setup_wizard_page__is_all_steps_completed() ) { | |
| 89 | + return false; | |
| 90 | + } | |
| 91 | + | |
| 92 | + if ( function_exists( 'wpbc_is_setup_wizard_page' ) && wpbc_is_setup_wizard_page() ) { | |
| 93 | + return true; | |
| 94 | + } | |
| 95 | + | |
| 96 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context. | |
| 97 | + $setup_context = isset( $_GET['wpbc_setup'] ) && is_scalar( $_GET['wpbc_setup'] ) | |
| 98 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context. | |
| 99 | + ? sanitize_text_field( wp_unslash( $_GET['wpbc_setup'] ) ) | |
| 100 | + : ''; | |
| 101 | + | |
| 102 | + if ( '1' === $setup_context ) { | |
| 103 | + return true; | |
| 104 | + } | |
| 105 | + | |
| 106 | + $steps_is_done = get_bk_option( 'booking_setup_wizard_page_steps_is_done' ); | |
| 107 | + | |
| 108 | + if ( ! is_array( $steps_is_done ) ) { | |
| 109 | + return false; | |
| 110 | + } | |
| 111 | + | |
| 112 | + foreach ( $steps_is_done as $is_step_done ) { | |
| 113 | + if ( ! empty( $is_step_done ) ) { | |
| 114 | + return true; | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + return false; | |
| 119 | +} | |
| 120 | + | |
| 121 | + | |
| 122 | +/** | |
| 123 | + * Check whether the current request explicitly targets one Setup Wizard step. | |
| 124 | + * | |
| 125 | + * This read-only request check is intentionally independent from saved wizard | |
| 126 | + * completion state. It lets an authorized user follow an explicit external | |
| 127 | + * setup URL without causing ordinary administration-page visits to reopen the | |
| 128 | + * completed wizard. | |
| 129 | + * | |
| 130 | + * @param string $step_name Expected Setup Wizard step identifier. | |
| 131 | + * | |
| 132 | + * @return bool True when the current URL explicitly requests the step. | |
| 133 | + */ | |
| 134 | +function wpbc_setup_wizard_page__has_explicit_step_context( $step_name ) { | |
| 135 | + | |
| 136 | + $step_name = sanitize_key( (string) $step_name ); | |
| 137 | + | |
| 138 | + if ( '' === $step_name ) { | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + | |
| 142 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context. | |
| 143 | + $setup_context = isset( $_GET['wpbc_setup'] ) && is_scalar( $_GET['wpbc_setup'] ) | |
| 144 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context. | |
| 145 | + ? sanitize_text_field( wp_unslash( $_GET['wpbc_setup'] ) ) | |
| 146 | + : ''; | |
| 147 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context. | |
| 148 | + $request_step = isset( $_GET['wpbc_setup_step'] ) && is_scalar( $_GET['wpbc_setup_step'] ) | |
| 149 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context. | |
| 150 | + ? sanitize_key( wp_unslash( $_GET['wpbc_setup_step'] ) ) | |
| 151 | + : ''; | |
| 152 | + | |
| 153 | + return '1' === $setup_context && $step_name === $request_step; | |
| 154 | +} | |
| 155 | + | |
| 156 | + | |
| 157 | +/** | |
| 158 | + * Check whether the current request is one explicit external Setup Wizard step. | |
| 159 | + * | |
| 160 | + * The setup context flag prevents ordinary visits to the same administration | |
| 161 | + * page from receiving wizard-only defaults. | |
| 162 | + * | |
| 163 | + * @param string $step_name Expected Setup Wizard step identifier. | |
| 164 | + * | |
| 165 | + * @return bool True when the unfinished wizard explicitly requested the step. | |
| 166 | + */ | |
| 167 | +function wpbc_setup_wizard_page__is_active_step( $step_name ) { | |
| 168 | + | |
| 169 | + $step_name = sanitize_key( (string) $step_name ); | |
| 170 | + | |
| 171 | + if ( '' === $step_name || ! wpbc_setup_wizard_page__is_in_progress() ) { | |
| 172 | + return false; | |
| 173 | + } | |
| 174 | + | |
| 175 | + return wpbc_setup_wizard_page__has_explicit_step_context( $step_name ); | |
| 176 | +} | |
| 58 | 177 | |
| 59 | 178 | /** |
| 60 | 179 | * Is user can access Wizard Setup page ? |
| 61 | 180 | * @return bool |
| @@ -194,57 +313,21 @@ | ||
| 194 | 313 | } |
| 195 | 314 | |
| 196 | 315 | |
| 197 | 316 | |
| 198 | -//TODO: Left Menu - TEMP . Delete it ? | |
| 199 | 317 | function wpbc_setup_wizard_page__get_left_navigation_menu_arr(){ |
| 200 | 318 | |
| 201 | 319 | $navigation_menu_arr = array(); |
| 320 | + $setup_steps = new WPBC_SETUP_WIZARD_STEPS(); | |
| 202 | 321 | |
| 203 | - $navigation_menu_arr['general_info'] = array( | |
| 204 | - 'title' => __( 'General Info', 'booking' ), | |
| 205 | - 'icon' => 'wpbc_icn_check wpbc_icn_dashboard0 wpbc_icn_task_alt0 0wpbc_icn_circle_outline', | |
| 206 | - 'class' => '', | |
| 207 | - //'style' => 'cursor:not-allowed;', | |
| 208 | - //'a_style' => 'pointer-events: none;', | |
| 209 | - 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'general_info' } );" | |
| 210 | - ,'right_icon' => array( | |
| 211 | - 'icon' => '', | |
| 212 | - 'text' => __('Done', 'booking'), | |
| 213 | - 'action' => "console.log( this );", | |
| 214 | - ) | |
| 215 | - | |
| 216 | - ); | |
| 217 | - $navigation_menu_arr['optional_other_settings'] = array( | |
| 218 | - 'title' => __( 'Bookings Type', 'booking' ), | |
| 219 | - 'icon' => 'wpbc-bi-calendar2-range 0wpbc_icn_radio_button_checked', | |
| 220 | - 'class' => '', | |
| 221 | - //'a_style' => 'color: var(--wpbc_settings__nav_menu_left__active_border_color);', | |
| 222 | - 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'optional_other_settings' } );" | |
| 223 | - ); | |
| 224 | - $navigation_menu_arr['next_step'] = array( | |
| 225 | - 'title' => '',//__( 'Bookings Type', 'booking' ), | |
| 226 | - 'icon' => 'wpbc-bi-three-dots 0wpbc_icn_radio_button_unchecked', | |
| 227 | - 'class' => '', | |
| 228 | - 'a_style' => 'pointer-events: none;cursor:not-allowed;', | |
| 229 | - 'action' => "wpbc_navigation_click_show_section(this,'#wpbc_general_settings_calendar_metabox' );" | |
| 230 | - ); | |
| 231 | -// $navigation_menu_arr['booking_notification'] = array( | |
| 232 | -// 'title' => __( 'Publishing', 'booking' ), | |
| 233 | -// 'icon' => 'wpbc-bi-calendar2-range', | |
| 234 | -// 'class' => 'wpbc_top_border', | |
| 235 | -// 'action' => "wpbc_navigation_click_show_section(this,'#wpbc_general_settings_calendar_metabox' );", | |
| 236 | -// 'right_icon' => array( | |
| 237 | -// 'icon' => 'wpbc_icn_navigate_next expand_more', | |
| 238 | -// 'action' => "console.log( this );", | |
| 239 | -// ) | |
| 240 | -// ); | |
| 241 | -// $navigation_menu_arr['booking_form'] = array( | |
| 242 | -// 'title' => __( 'Booking Form', 'booking' ), | |
| 243 | -// 'icon' => 'wpbc_icn_dashboard', | |
| 244 | -// 'class' => 'wpbc_sub_option', | |
| 245 | -// 'action' => "wpbc_navigation_click_show_section(this,'#wpbc_general_settings_calendar_metabox' );" | |
| 246 | -// ); | |
| 322 | + foreach ( array_keys( $setup_steps->get_steps_arr() ) as $step_name ) { | |
| 323 | + $navigation_menu_arr[ $step_name ] = array( | |
| 324 | + 'title' => function_exists( 'wpbc_setup_wizard__get_step_title' ) ? wpbc_setup_wizard__get_step_title( $step_name ) : $step_name, | |
| 325 | + 'icon' => 'wpbc_icn_circle_outline', | |
| 326 | + 'class' => '', | |
| 327 | + 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'" . esc_js( $step_name ) . "' } );", | |
| 328 | + ); | |
| 329 | + } | |
| 247 | 330 | |
| 248 | 331 | return $navigation_menu_arr; |
| 249 | 332 | } |
| 250 | 333 | |