PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
← All changes | includes/page-setup/setup__page.php +224 -53 11.111.8.3 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /*
3 3 * @package: AJX_Setup_Wizard Page
4 4 * @category: Initial setup and plugin customization
@@ -9,41 +9,15 @@
9 9 // FixIn: 10.2.0.1.
10 10 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
11 11
12 12 /**
13 - * == How to add a new step ? ==
14 - *
15 - * 1. Create and include (bellow) a new files:
16 - * require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/form_structure__tpl.php' );
17 - * require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/form_structure__action.php' );
18 - *
19 - * 2) ../includes/page-setup/setup_steps.php
20 - * - Add a new step structure in init_steps_data()
21 - *
22 - * 3)../includes/page-setup/setup_ajax.php
23 - * - Add validation option 'save_and_continue__form_structure' in wpbc_setup_wizard_page__request_rules_structure()
24 - * - Add save action in ajax_WPBC_AJX_SETUP_WIZARD_PAGE :
25 - * case 'save_and_continue__form_structure': $
26 - * if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
27 - * $cleaned_data = wpbc_template__form_structure__action_validate_data( $_POST['all_ajx_params']['step_data'] );
28 - * wpbc_setup__update__form_structure( $cleaned_data );
29 - * }
30 - * $setup_steps->db__set_step_as_completed( 'form_structure' );
31 - * break;
32 - * - Optional. Add loading booking form:
33 - * switch ( $cleaned_request_params['current_step'] ) {
34 - * case 'form_structure':
35 - * 4) ../includes/page-setup/setup_templates.php
36 - * - Add loading template in function wpbc_template__stp_wiz__main_content() {
37 - * case 'form_structure':
38 - * template__main_section = wp.template( 'wpbc_stp_wiz__template__form_structure' );
39 - * break;
40 - * - include template in function hook__load_templates_at_footer( $page ):
41 - * wpbc_stp_wiz__template__form_structure();
13 + * The setup wizard renders only the introductory steps on this page. Profile-specific configuration after
14 + * "Booking Type" is routed to existing WPBC admin pages and controlled by the floating setup bar.
42 15 */
43 16
44 17
45 18 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_templates.php' );
19 +require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_profiles.php' );
46 20 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/01.welcome__tpl.php' );
47 21
48 22 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/02.general_info__tpl.php' );
49 23 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/02.general_info__action.php' );
@@ -53,29 +27,12 @@
53 27
54 28 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/04.bookings_types__tpl.php' );
55 29 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/04.bookings_types__action.php' );
56 30
57 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/05.form_structure__tpl.php' );
58 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/05.form_structure__action.php' );
59 -
60 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/06.cal_availability__tpl.php' );
61 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/06.cal_availability__action.php' );
62 -
63 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/07.color_theme__tpl.php' );
64 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/07.color_theme__action.php' );
65 -
66 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/08.optional_other_settings__tpl.php' );
67 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/08.optional_other_settings__action.php' );
68 -
69 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/09.wizard_publish__tpl.php' );
70 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/09.wizard_publish__action.php' );
71 -
72 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/10.get_started__tpl.php' );
73 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/templates/10.get_started__action.php' );
74 -
75 31 require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_steps.php' );
76 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_ajax.php' );
77 -require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_support.php' );
32 +require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_ajax.php' );
33 +require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/setup_support.php' );
34 +require_once( WPBC_PLUGIN_DIR . '/includes/page-setup/first-run-popup.php' );
78 35
79 36 /** Show Content
80 37 * Update Content
81 38 * Define Slug
@@ -101,9 +58,11 @@
101 58 public function tabs() {
102 59
103 60 $tabs = array();
104 61 $tabs[ 'step_01' ] = array(
62 + 'is_force_full_screen' => true, // true | false. Force full screen independently from user preference.
105 63 'left_navigation__default_view_mode' => 'none', // '' | 'min' | 'compact' | 'max' | 'none'. By default value is: ''.
64 + 'left_navigation__force_view_mode' => 'none', // '' | 'min' | 'compact' | 'max' | 'none'. Force sidebar mode independently from user preference.
106 65 'title' => __( 'Setup', 'booking' ) // Title of TAB
107 66 , 'hint' => false//__( 'Setup', 'booking' ) . ' - ' . 'Booking Calendar' // Hint
108 67 , 'page_title' => false//__( 'Setup', 'booking' ) . ' - ' . 'Booking Calendar' // Title of Page
109 68 , 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
@@ -291,9 +250,9 @@
291 250 ?></script><?php
292 251
293 252 /**
294 253 * JS Examples of showing specific Step:
295 - * wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'optional_other_settings' } );
254 + * wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'date_availability' } );
296 255 *
297 256 * wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'general_info' } );
298 257 */
299 258 }
@@ -329,8 +288,9 @@
329 288 if ( isset( $_REQUEST['wpbc_setup_wizard'] ) && 'completed' === $_REQUEST['wpbc_setup_wizard'] ) {
330 289
331 290 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
332 291 $setup_steps->db__set_all_steps_as( true );
292 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( false );
333 293
334 294 return true;
335 295 }
336 296
@@ -350,13 +310,224 @@
350 310 // Delete from DB
351 311 $is_reseted = $user_request->user_request_params__db_delete();
352 312
353 313 // Clear All Steps Mark as Undone
354 - $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
355 - $setup_steps->db__set_all_steps_as( false );
314 + $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
315 + $setup_steps->db__set_all_steps_as( false );
316 + update_bk_option( 'booking_wizard_data', array() );
317 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( true );
356 318
357 319 return true;
358 320 }
359 321
322 + $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
323 + $steps_arr = $setup_steps->get_steps_arr();
324 + $request_step = '';
325 +
326 + if ( 'On' === get_bk_option( 'booking_setup_wizard_page_is_completed' ) ) {
327 + // A completed wizard has no authority over the administrator's later Full Screen preference.
328 + return true;
329 + }
330 +
331 + if ( wpbc_is_setup_wizard_page() ) {
332 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( true );
333 + }
334 +
335 + $is_external_setup_flow_started = $setup_steps->db__is_step_completed( 'bookings_types' );
336 +
337 + // Persist the real setup step when the user lands on an external WPBC admin page.
338 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
339 + if ( isset( $_REQUEST['wpbc_setup_step'] ) ) {
340 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
341 + $request_step_from_request = sanitize_key( wp_unslash( $_REQUEST['wpbc_setup_step'] ) );
342 + if ( isset( $steps_arr[ $request_step_from_request ] ) ) {
343 + $request_step = $request_step_from_request;
344 + $setup_steps->db__save_current_step_name( $request_step );
345 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( ( ! wpbc_setup_wizard__is_internal_step( $request_step ) ) && ( 'get_started' !== $request_step ) );
346 + }
347 + }
348 +
349 + if ( $is_external_setup_flow_started && function_exists( 'wpbc_setup_wizard__detect_step_from_admin_request' ) ) {
350 + $detected_step = wpbc_setup_wizard__detect_step_from_admin_request();
351 + if ( empty( $request_step ) && ! empty( $detected_step ) && isset( $steps_arr[ $detected_step ] ) ) {
352 + $setup_steps->db__save_current_step_name( $detected_step );
353 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( ! wpbc_setup_wizard__is_internal_step( $detected_step ) );
354 + }
355 + }
356 +
357 + $is_ajax_request = ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX );
358 +
359 + // Existing settings pages submit their own forms. This flag lets the setup bar remember that save across reloads.
360 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
361 + if ( isset( $_REQUEST['wpbc_setup_saved_step'] ) && ! $is_ajax_request ) {
362 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
363 + $saved_step = sanitize_key( wp_unslash( $_REQUEST['wpbc_setup_saved_step'] ) );
364 + if ( isset( $steps_arr[ $saved_step ] ) ) {
365 + $setup_steps->db__set_step_as_saved( $saved_step, true );
366 + $setup_steps->db__save_current_step_name( $saved_step );
367 +
368 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
369 + $continue_after_save = isset( $_REQUEST['wpbc_setup_continue_after_save'] )
370 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
371 + ? sanitize_text_field( wp_unslash( $_REQUEST['wpbc_setup_continue_after_save'] ) )
372 + : '';
373 + if ( '1' === $continue_after_save ) {
374 + wpbc_redirect( $setup_steps->get_step_continue_url( $saved_step ) );
375 + exit;
376 + }
377 + }
378 + }
379 +
380 + // Continue from an existing WPBC settings page to the next setup target.
381 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
382 + if ( isset( $_REQUEST['wpbc_setup_wizard'] ) && 'continue' === $_REQUEST['wpbc_setup_wizard'] ) {
383 +
384 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
385 + $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
386 + if ( ! wp_verify_nonce( $nonce, 'wpbc_settings_url_nonce' ) ) {
387 + return false;
388 + }
389 +
390 + $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
391 + $steps_arr = $setup_steps->get_steps_arr();
392 + $current_step = $setup_steps->get_saved_current_step_name();
393 + $has_explicit_step_context = false;
394 +
395 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
396 + if ( isset( $_REQUEST['wpbc_setup_step'] ) ) {
397 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
398 + $request_step = sanitize_key( wp_unslash( $_REQUEST['wpbc_setup_step'] ) );
399 + if ( isset( $steps_arr[ $request_step ] ) ) {
400 + $current_step = $request_step;
401 + $has_explicit_step_context = true;
402 + }
403 + }
404 +
405 + // Prefer the step detected on the page that rendered the setup bar. This avoids stale saved state taking over.
406 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
407 + if ( isset( $_REQUEST['wpbc_setup_from_page_step'] ) ) {
408 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
409 + $from_page_step = sanitize_key( wp_unslash( $_REQUEST['wpbc_setup_from_page_step'] ) );
410 + if ( isset( $steps_arr[ $from_page_step ] ) ) {
411 + $current_step = $from_page_step;
412 + $has_explicit_step_context = true;
413 + if ( 'form_structure' === $current_step ) {
414 + $setup_steps->db__set_step_as_saved( $current_step, true );
415 + }
416 + }
417 + }
418 +
419 + if ( ( ! $has_explicit_step_context ) && function_exists( 'wpbc_setup_wizard__detect_step_from_admin_url' ) ) {
420 + $referer_step = wpbc_setup_wizard__detect_step_from_admin_url( wp_get_referer() );
421 + if ( ! empty( $referer_step ) && isset( $steps_arr[ $referer_step ] ) ) {
422 + $current_step = $referer_step;
423 + if ( 'form_structure' === $current_step ) {
424 + $setup_steps->db__set_step_as_saved( $current_step, true );
425 + }
426 + }
427 + }
428 +
429 + $setup_steps->db__save_current_step_name( $current_step );
430 +
431 + if (
432 + isset( $steps_arr[ $current_step ] )
433 + && 'manual_save_required' === $setup_steps->get_step_save_behavior( $current_step )
434 + && ! $setup_steps->db__is_step_saved( $current_step )
435 + ) {
436 + wpbc_redirect( add_query_arg( 'wpbc_setup_save_required', '1', $setup_steps->get_step_target_url( $current_step ) ) );
437 + exit;
438 + }
439 +
440 + if ( isset( $steps_arr[ $current_step ] ) ) {
441 + $setup_steps->db__set_step_as_completed( $current_step );
442 + }
443 +
444 + $next_step = isset( $steps_arr[ $current_step ]['next'] ) ? $steps_arr[ $current_step ]['next'] : '';
445 + if ( ( empty( $next_step ) || ( 'welcome' === $next_step ) ) && function_exists( 'wpbc_setup_wizard__get_next_step_name' ) ) {
446 + $route_next_step = wpbc_setup_wizard__get_next_step_name( $current_step );
447 + if ( ! empty( $route_next_step ) && isset( $steps_arr[ $route_next_step ] ) ) {
448 + $next_step = $route_next_step;
449 + }
450 + }
451 +
452 + if ( empty( $next_step ) || ( 'welcome' === $next_step ) ) {
453 + if ( 'get_started' === $current_step || 'complete' === $setup_steps->get_step_save_behavior( $current_step ) ) {
454 + $setup_steps->db__set_all_steps_as( true );
455 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( false );
456 + wpbc_redirect( wpbc_get_bookings_url() );
457 + exit;
458 + }
459 +
460 + if ( 'get_started' !== $current_step ) {
461 + $fallback_step = $setup_steps->get_active_step_name();
462 + if (
463 + ( ! empty( $fallback_step ) )
464 + && isset( $steps_arr[ $fallback_step ] )
465 + && ( $fallback_step !== $current_step )
466 + && ! $setup_steps->db__is_step_completed( $fallback_step )
467 + ) {
468 + $setup_steps->db__save_current_step_name( $fallback_step );
469 + wpbc_redirect( $setup_steps->get_step_target_url( $fallback_step ) );
470 + exit;
471 + }
472 + }
473 +
474 + wpbc_setup_wizard__set_full_screen_mode_for_current_user( false );
475 + wpbc_redirect( wpbc_get_bookings_url() );
476 + exit;
477 + }
478 +
479 + $setup_steps->db__reset_steps_from( $next_step );
480 +
481 + $request_params_to_save = wpbc_setup_wizard_page__get_cleaned_params__saved_request_default();
482 + if ( ! is_array( $request_params_to_save ) ) {
483 + $request_params_to_save = wpbc_setup_wizard_page__get__request_values__default();
484 + }
485 + $request_params_to_save['current_step'] = $next_step;
486 + if (
487 + isset( $steps_arr[ $next_step ] )
488 + && 'manual_save_required' === $setup_steps->get_step_save_behavior( $next_step )
489 + && ! $setup_steps->db__is_step_completed( $next_step )
490 + ) {
491 + $setup_steps->db__set_step_as_saved( $next_step, false );
492 + }
493 +
494 + $user_request = new WPBC_AJX__REQUEST( array(
495 + 'db_option_name' => 'booking_setup_wizard_page_request_params',
496 + 'user_id' => wpbc_get_current_user_id(),
497 + 'request_rules_structure' => wpbc_setup_wizard_page__request_rules_structure()
498 + )
499 + );
500 + $user_request->user_request_params__db_save( $request_params_to_save );
501 +
502 + wpbc_redirect( $setup_steps->get_step_target_url( $next_step ) );
503 + exit;
504 + }
505 +
506 + // In the guided setup architecture, Step 5+ is configured on existing WPBC admin pages.
507 + if (
508 + wpbc_is_setup_wizard_page()
509 + && ( ! ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() ) )
510 + ) {
511 + $current_step = $setup_steps->get_saved_current_step_name();
512 +
513 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
514 + if ( isset( $_REQUEST['current_step'] ) ) {
515 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
516 + $request_step = sanitize_key( wp_unslash( $_REQUEST['current_step'] ) );
517 + if ( isset( $steps_arr[ $request_step ] ) ) {
518 + $current_step = $request_step;
519 + }
520 + }
521 +
522 + if (
523 + isset( $steps_arr[ $current_step ]['is_external'] )
524 + && $steps_arr[ $current_step ]['is_external']
525 + ) {
526 + wpbc_redirect( $setup_steps->get_step_target_url( $current_step ) );
527 + exit;
528 + }
529 + }
530 +
360 531 return false;
361 532 }
362 -add_action( 'init', 'wpbc_setup_wizard_page__force_in_get' );
533 +add_action( 'init', 'wpbc_setup_wizard_page__force_in_get' );