PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
11.8.4 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 All 204 releases
← All changes | core/wpbc-activation.php +82 -10 11.511.8.4 View file →
@@ -13,8 +13,59 @@
13 13
14 14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15 15
16 16
17 +/**
18 + * Evaluate whether the current activation starts from a genuinely empty install.
19 + *
20 + * Both signals are required. A missing version option by itself is not reliable,
21 + * because older installations or interrupted upgrades can still have Booking
22 + * Calendar tables. A missing table by itself is also insufficient when stored
23 + * installation metadata remains.
24 + *
25 + * @param mixed $stored_version Stored Booking Calendar version, or false when absent.
26 + * @param bool $booking_table_exists Whether the canonical booking table exists.
27 + *
28 + * @return bool True only when neither installation signal exists.
29 + */
30 +function wpbc_is_plugin_initial_install_state( $stored_version, $booking_table_exists ) {
31 +
32 + return ( false === $stored_version ) && ! (bool) $booking_table_exists;
33 +}
34 +
35 +
36 +/**
37 + * Check whether the active activation request is a genuine first installation.
38 + *
39 + * The result is cached before activation creates tables or saves
40 + * `booking_version_num`, allowing later activation callbacks to consume the same
41 + * immutable request-scoped decision. For later administration requests, use the
42 + * persisted first-install marker owned by the Setup Wizard instead.
43 + *
44 + * @return bool True during a genuine first-install activation; otherwise false.
45 + */
46 +function wpbc_is_plugin_initial_install() {
47 +
48 + static $is_initial_install = null;
49 +
50 + if ( null !== $is_initial_install ) {
51 + return $is_initial_install;
52 + }
53 +
54 + if ( ! function_exists( 'wpbc_is_table_exists' ) ) {
55 + $is_initial_install = false;
56 + return $is_initial_install;
57 + }
58 +
59 + $is_initial_install = wpbc_is_plugin_initial_install_state(
60 + get_option( 'booking_version_num', false ),
61 + wpbc_is_table_exists( 'booking' )
62 + );
63 +
64 + return $is_initial_install;
65 +}
66 +
67 +
17 68 /** Activation & Deactivation of Booking Calendar */
18 69 class WPBC_BookingInstall extends WPBC_Install {
19 70
20 71 /**
@@ -72,8 +123,11 @@
72 123 // FixIn: 9.9.0.13.
73 124 if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_m' ) ) && ( ! wpbc_is_table_exists( 'booking_seasons' ) ) ) {
74 125 $is_make_activation = true;
75 126 }
127 + if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_m' ) ) && ( wpbc_is_field_in_table_exists( 'booking_seasons', 'season_color' ) == 0 ) ) {
128 + $is_make_activation = true;
129 + }
76 130 if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_l' ) ) && ( ! wpbc_is_table_exists( 'booking_coupons' ) ) ) {
77 131 $is_make_activation = true;
78 132 }
79 133 if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_multiuser' ) ) && ( wpbc_is_field_in_table_exists( 'booking_coupons', 'users' ) == 0 ) ) {
@@ -187,12 +241,9 @@
187 241 function wpbc_booking_activate() {
188 242
189 243 wpbc_load_translation();
190 244
191 - $is_new_install = (
192 - false === get_option( 'booking_version_num', false )
193 - && ! wpbc_is_table_exists( 'booking' )
194 - );
245 + $is_new_install = wpbc_is_plugin_initial_install();
195 246
196 247 make_bk_action( 'wpbc_before_activation' );
197 248
198 249
@@ -202,12 +253,18 @@
202 253
203 254 // -----------------------------------------------------------------------------------------------------------------
204 255 // Options
205 256 // -----------------------------------------------------------------------------------------------------------------
206 - $default_options_to_add = wpbc_get_default_options();
257 + $default_options_to_add = wpbc_get_default_options();
207 258 // Existing installations retain their saved value; add_bk_option() never overwrites it during upgrades.
208 259 if ( $is_new_install ) {
209 260 $default_options_to_add['booking_form_accent_enabled'] = 'On';
261 + $default_options_to_add['booking_setup_wizard_initial_install'] = 'On';
262 + $default_options_to_add['booking_setup_wizard_first_run_prompt'] = 'On';
263 + $default_options_to_add['booking_setup_wizard_booking_pages_prompt'] = 'On';
264 + if ( ! class_exists( 'wpdev_bk_personal' ) ) {
265 + $default_options_to_add['booking_resources_catalog_default_view'] = 'publishing';
266 + }
210 267 }
211 268 // TODO: for Import / Export options, we can use this function to get all option_names and then just get the real values from the wp_options table.
212 269 make_bk_action( 'wpbc_before_activation__add_options', $default_options_to_add ); // FixIn: 9.6.2.11.
213 270
@@ -330,9 +387,13 @@
330 387 $sql_check_table = "SELECT booking_id as id FROM {$wpdb->prefix}booking ORDER BY booking_id DESC LIMIT 0, 100";
331 388
332 389 $res = $wpdb->get_results( $sql_check_table ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
333 390 foreach ( $res as $l ) {
334 - $wp_queries[] = "UPDATE {$wpdb->prefix}booking SET hash = MD5('" . time() . '_' . wp_rand( 1000, 1000000 ) . "') WHERE booking_id = " . $l->id; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
391 + $wp_queries[] = $wpdb->prepare(
392 + "UPDATE {$wpdb->prefix}booking SET hash = %s WHERE booking_id = %d",
393 + wpbc_hash__generate_booking_hash(),
394 + $l->id
395 + ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
335 396 }
336 397 }
337 398 }
338 399
@@ -386,9 +447,9 @@
386 447 if ( $is_insert_test_bookings ) {
387 448 // -- Test Booking #1 --
388 449 $is_appr = 1;
389 450 $wp_queries_sub = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date ) VALUES (
390 - 'text^name1^John~text^secondname1^Smith~text^email1^example-free@wpbookingcalendar.com~text^phone1^458-77-77~textarea^details1^This is a test booking showing booking for several days.', " . wpbc_sql_date_math_expr_explicit('', 'now') . " );";
451 + 'text^firstname1^John~text^secondname1^Smith~text^email1^example-free@wpbookingcalendar.com~text^phone1^458-77-77~textarea^details1^This is a test booking showing booking for several days.', " . wpbc_sql_date_math_expr_explicit('', 'now') . " );";
391 452 $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
392 453
393 454 $temp_id = $wpdb->insert_id;
394 455 $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates ( booking_id, booking_date, approved ) VALUES
@@ -399,9 +460,9 @@
399 460
400 461 // -- Test Booking #2 --
401 462 $is_appr = 0;
402 463 $wp_queries_sub = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date ) VALUES (
403 - 'text^name1^Emma~text^secondname1^Robinson~text^email1^example-free@wpbookingcalendar.com~text^phone1^999-77-77~textarea^details1^This is a test booking showing booking for several days.', " . wpbc_sql_date_math_expr_explicit('', 'now') . " );";
464 + 'text^firstname1^Emma~text^secondname1^Robinson~text^email1^example-free@wpbookingcalendar.com~text^phone1^999-77-77~textarea^details1^This is a test booking showing booking for several days.', " . wpbc_sql_date_math_expr_explicit('', 'now') . " );";
404 465 $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
405 466
406 467 $temp_id = $wpdb->insert_id;
407 468 $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates ( booking_id, booking_date, approved ) VALUES
@@ -415,9 +476,9 @@
415 476 $is_appr = 1;
416 477 $start_time = '10:00';
417 478 $end_time = '10:30';
418 479 $wp_queries_sub = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date, is_new ) VALUES (
419 - 'selectbox^rangetime1^".$start_time." - ".$end_time."~text^name1^Sophia~text^secondname1^Robinson~text^email1^example-free@wpbookingcalendar.com~text^phone1^458-77-77~textarea^details1^This is a test booking showing a one day time slot booking.', " . wpbc_sql_date_math_expr_explicit('', 'now') . ", 0 );";
480 + 'selectbox^rangetime1^".$start_time." - ".$end_time."~text^firstname1^Sophia~text^secondname1^Robinson~text^email1^example-free@wpbookingcalendar.com~text^phone1^458-77-77~textarea^details1^This is a test booking showing a one day time slot booking.', " . wpbc_sql_date_math_expr_explicit('', 'now') . ", 0 );";
420 481 $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
421 482
422 483 $temp_id = $wpdb->insert_id;
423 484
@@ -621,8 +682,14 @@
621 682
622 683 // FixIn: 9.6.3.5.
623 684 $default_options['booking_setup_wizard_page_steps_is_done'] = '';
624 685 $mu_option4delete[]='booking_setup_wizard_page_steps_is_done';
686 + $default_options['booking_setup_wizard_initial_install'] = 'Off';
687 + $mu_option4delete[] = 'booking_setup_wizard_initial_install';
688 + $default_options['booking_setup_wizard_first_run_prompt'] = 'Off';
689 + $mu_option4delete[] = 'booking_setup_wizard_first_run_prompt';
690 + $default_options['booking_setup_wizard_booking_pages_prompt'] = 'Off';
691 + $mu_option4delete[] = 'booking_setup_wizard_booking_pages_prompt';
625 692
626 693 $default_options['booking_admin_cal_count'] = ($is_demo) ? '3' : '2';
627 694 $mu_option4delete[]='booking_admin_cal_count'; // $multiuser_general_option[] = implode( '', array_keys( array_slice( $default_options, -1 ) ) );
628 695 $default_options['booking_skin'] = '/css/skins/25_5__square_1.css'; // FixIn: 10.11.4.2.
@@ -629,8 +696,12 @@
629 696 $mu_option4delete[]='booking_skin';
630 697 // FixIn: 9.6.3.5.
631 698 $default_options['booking_listing_default_view_mode'] = 'vm_booking_listing'; // 'vm_calendar'; // FixIn: 9.6.3.5.
632 699 $mu_option4delete[]='booking_listing_default_view_mode';
700 + $default_options['booking_admin_edit_booking_mode'] = 'popup';
701 + $mu_option4delete[]='booking_admin_edit_booking_mode';
702 + $default_options['booking_resources_catalog_default_view'] = '';
703 + $mu_option4delete[] = 'booking_resources_catalog_default_view';
633 704
634 705 $default_options['booking_view_days_num'] = ( ( ! class_exists( 'wpdev_bk_personal' ) ) ? '90' : '30' );
635 706 $mu_option4delete[]='booking_view_days_num';
636 707 // FixIn: 8.9.4.3.
@@ -660,9 +731,10 @@
660 731
661 732 // FixIn: 10.13.1.5.
662 733 $default_options['booking_is_use_phone_validation'] = 'Off';
663 734 $mu_option4delete[]='booking_is_use_phone_validation';
664 - $default_options['booking_date_format'] = get_option( 'date_format' );
735 + $wordpress_date_format = get_option( 'date_format' );
736 + $default_options['booking_date_format'] = ( 'F j, Y' === $wordpress_date_format ) ? 'j M Y' : $wordpress_date_format;
665 737 $mu_option4delete[]='booking_date_format';
666 738 $default_options['booking_time_format'] = get_option( 'time_format' ); //'H:i';
667 739 $mu_option4delete[]='booking_time_format';
668 740