PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 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 All 205 releases
← All changes | core/wpbc-activation.php +558 -742 10.10.1 → 11.9 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 /**
@@ -55,533 +106,43 @@
55 106
56 107 return $links;
57 108
58 109 }
59 -
60 - /** Check if was updated from lower to high version */
61 - public function is_update_from_lower_to_high_version() {
62 -
63 - $is_make_activation = false;
64 110
65 - // Check conditions for different version about Upgrade
66 - if ( ( class_exists( 'wpdev_bk_personal' ) ) && ( ! wpbc_is_table_exists( 'bookingtypes' ) ) ) {
67 - $is_make_activation = true;
68 - }
69 - if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_s' ) ) && ( wpbc_is_field_in_table_exists( 'booking', 'pay_request' ) == 0 ) ) {
70 - $is_make_activation = true;
71 - }
72 - // FixIn: 9.9.0.13.
73 - if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_m' ) ) && ( ! wpbc_is_table_exists( 'booking_seasons' ) ) ) {
74 - $is_make_activation = true;
75 - }
76 - if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_l' ) ) && ( ! wpbc_is_table_exists( 'booking_coupons' ) ) ) {
77 - $is_make_activation = true;
78 - }
79 - if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_multiuser' ) ) && ( wpbc_is_field_in_table_exists( 'booking_coupons', 'users' ) == 0 ) ) {
80 - $is_make_activation = true;
81 - }
82 - return $is_make_activation;
83 - }
111 + /** Check if was updated from lower to high version */
112 + public function is_update_from_lower_to_high_version() {
84 113
85 -}
114 + $is_make_activation = false;
86 115
116 + // Check conditions for different version about Upgrade
117 + if ( ( class_exists( 'wpdev_bk_personal' ) ) && ( ! wpbc_is_table_exists( 'bookingtypes' ) ) ) {
118 + $is_make_activation = true;
119 + }
120 + if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_s' ) ) && ( wpbc_is_field_in_table_exists( 'booking', 'pay_request' ) == 0 ) ) {
121 + $is_make_activation = true;
122 + }
123 + // FixIn: 9.9.0.13.
124 + if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_m' ) ) && ( ! wpbc_is_table_exists( 'booking_seasons' ) ) ) {
125 + $is_make_activation = true;
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 + }
130 + if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_biz_l' ) ) && ( ! wpbc_is_table_exists( 'booking_coupons' ) ) ) {
131 + $is_make_activation = true;
132 + }
133 + if ( ( ! $is_make_activation ) && ( class_exists( 'wpdev_bk_multiuser' ) ) && ( wpbc_is_field_in_table_exists( 'booking_coupons', 'users' ) == 0 ) ) {
134 + $is_make_activation = true;
135 + }
87 136
88 -// <editor-fold defaultstate="collapsed" desc=" Examples Data for Demos " >
137 + return $is_make_activation;
138 + }
89 139
90 -function wpbc_create_examples_4_demo( $my_bk_types = array() ){
91 -
92 - global $wpdb;
93 - $version = wpbc_get_plugin_version_type();
94 -
95 - if (class_exists('wpdev_bk_multiuser')) {
96 -
97 - if ( empty( $my_bk_types ) ) {
98 - $my_bk_types = array( 13, 14, 15, 16, 17 ); // The booking resources with these IDs are exist in the Demo sites
99 - } else {
100 - shuffle( $my_bk_types );
101 - }
102 -
103 - // Get NUMBER of Bookings.
104 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
105 - $bookings_count = $wpdb->get_results( "SELECT COUNT(*) as count FROM {$wpdb->prefix}booking as bk WHERE bk.trash != 1" );
106 -
107 - if (count($bookings_count)>0) $bookings_count = $bookings_count[0]->count ;
108 - if ($bookings_count>=20) return;
109 -
110 - if ( ( ( defined( 'WP_BK_BETA_DATA_FILL_AS' ) ) && ( 'BL' === WP_BK_BETA_DATA_FILL_AS ) ) && ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ) {
111 - update_bk_option( 'booking_range_selection_time_is_active', 'On' );
112 - update_bk_option( 'booking_range_selection_start_time', '14:00' );
113 - update_bk_option( 'booking_range_selection_end_time', '12:00' );
114 -
115 - update_bk_option( 'booking_is_delete_if_deactive', 'On');
116 - }
117 -
118 - $max_num_bookings = 5; // How many bookings exist per resource
119 - foreach ($my_bk_types as $resource_id) { // Loop all resources
120 - $bk_type = $resource_id; // Booking Resource
121 -
122 - if ( ( ( defined( 'WP_BK_BETA_DATA_FILL_AS' ) ) && ( 'BL' === WP_BK_BETA_DATA_FILL_AS ) ) && ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ) {
123 - $min_days = 3;
124 - $max_days = 7;
125 - } else {
126 - $min_days = 1; // FixIn: 10.0.0.51.
127 - $max_days = 1; // FixIn: 10.0.0.51.
128 - }
129 -
130 - $evry_one = $max_days + wp_rand( 1, 5 ); // Multiplier of interval between 2 dates of different bookings
131 - $days_start_shift = wp_rand( $max_days, ( 3 * $max_days ) );//(ceil($max_num_bookings/2)) * $max_days; // How long far ago we are start bookings
132 -
133 - // Fill Development server by initial bookings
134 - if ( ( ( defined( 'WP_BK_BETA_DATA_FILL' ) ) && ( WP_BK_BETA_DATA_FILL > 0 ) ) && ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ) {
135 - $evry_one = $min_days + wp_rand( 1, 7 );//3*$max_days+wp_rand(1,7); // Multiplier of interval between 2 dates of different bookings
136 - $days_start_shift = wp_rand( 2 * $max_days, ( 5 * $max_days ) ); //wp_rand(2*$max_days,(5*$max_days));//(ceil($max_num_bookings/2)) * $max_days; // How long far ago we are start bookings
137 - }
138 -
139 - for ( $i = 0; $i < $max_num_bookings; $i ++ ) {
140 -
141 - $is_appr = wp_rand(0,1); // Pending | Approved
142 - $num_days = wp_rand($min_days,$max_days); // Max Number of Dates for specific booking
143 -
144 - $second_name = wpbc_get_initial_values_4_demo('second_name');
145 - $city = wpbc_get_initial_values_4_demo('city');
146 - if ( ( ( defined( 'WP_BK_BETA_DATA_FILL_AS' ) ) && ( 'BL' === WP_BK_BETA_DATA_FILL_AS ) ) && ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ) {
147 - $start_time = '14:00';
148 - $end_time = '12:00';
149 - } else {
150 - $range_time = wpbc_get_initial_values_4_demo( 'rangetime' ); // FixIn: 10.0.0.51.
151 - $start_time = $range_time[0]; // FixIn: 10.0.0.51.
152 - $end_time = $range_time[1]; // FixIn: 10.0.0.51.
153 - }
154 -
155 - $form = '';
156 - $form .= 'selectbox-one^rangetime'.$bk_type.'^'.$start_time.' - '.$end_time.'~';
157 - $form .= 'text^name'.$bk_type.'^'.wpbc_get_initial_values_4_demo('name').'~';
158 - $form .= 'text^secondname'.$bk_type.'^'.$second_name.'~';
159 - $form .= 'text^email'.$bk_type.'^'.$second_name.'[email protected]~';
160 - $form .= 'text^address'.$bk_type.'^'.wpbc_get_initial_values_4_demo('adress').'~';
161 - $form .= 'text^city'.$bk_type.'^'.$city[0].'~';
162 - $form .= 'text^postcode'.$bk_type.'^'.wpbc_get_initial_values_4_demo('postcode').'~';
163 - $form .= 'text^country'.$bk_type.'^'.$city[1].'~';
164 - $form .= 'text^phone'.$bk_type.'^'.wpbc_get_initial_values_4_demo('phone').'~';
165 - $form .= 'selectbox-one^visitors'.$bk_type.'^1~';
166 - //$form .= 'checkbox^children'.$bk_type.'[]^0~';
167 - $form .= 'textarea^details'.$bk_type.'^'.wpbc_get_initial_values_4_demo('info').'~';
168 - $form .= 'coupon^coupon'.$bk_type.'^ ';
169 -
170 -
171 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, booking_type, cost, hash, modification_date ) VALUES
172 - ( '".$form."', ".$bk_type .", ".wp_rand(0,1000).", MD5('". time() . '_' . wp_rand(1000,1000000)."'), NOW() ) ;";
173 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
174 - $wpdb->query( $wp_bk_querie );
175 - $temp_id = $wpdb->insert_id;
176 -
177 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
178 - booking_id,
179 - booking_date,
180 - approved
181 - ) VALUES ";
182 - for ($d_num = 0; $d_num < $num_days; $d_num++) {
183 - $my_interval = ( $i*$evry_one + $d_num);
184 -
185 - if ( ( ( defined( 'WP_BK_BETA_DATA_FILL_AS' ) ) && ( 'BL' === WP_BK_BETA_DATA_FILL_AS ) ) && ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ) {
186 -
187 - if ( 'On' !== get_bk_option( 'booking_range_selection_time_is_active' ) ) {
188 - $wp_queries_sub .= "( " . $temp_id . ", DATE_ADD(CURDATE(), INTERVAL -" . $days_start_shift . " day) + INTERVAL " . $my_interval . " day ," . $is_appr . " ),";
189 - } else {
190 - if ( $d_num == 0 ) { // Check In
191 - $wp_queries_sub .= "( " . $temp_id . ", DATE_ADD(CURDATE(), INTERVAL -" . $days_start_shift . " day) + INTERVAL \"" . $my_interval . " " . $start_time . ":01\" DAY_SECOND ," . $is_appr . " ),";
192 - } elseif ( $d_num == ( $num_days - 1 ) ) { // Check Out
193 - $wp_queries_sub .= "( " . $temp_id . ", DATE_ADD(CURDATE(), INTERVAL -" . $days_start_shift . " day) + INTERVAL \"" . $my_interval . " " . $end_time . ":02\" DAY_SECOND ," . $is_appr . " ),";
194 - } else {
195 - $wp_queries_sub .= "( " . $temp_id . ", DATE_ADD(CURDATE(), INTERVAL -" . $days_start_shift . " day) + INTERVAL " . $my_interval . " day ," . $is_appr . " ),";
196 - }
197 - }
198 - } else {
199 - $wp_queries_sub .= "( " . $temp_id . ", DATE_ADD(CURDATE(), INTERVAL -" . $days_start_shift . " DAY) + INTERVAL \"" . $my_interval . " " . $start_time . ":01\" DAY_SECOND ," . $is_appr . " ),"; // FixIn: 10.0.0.51.
200 - $wp_queries_sub .= "( " . $temp_id . ", DATE_ADD(CURDATE(), INTERVAL -" . $days_start_shift . " DAY) + INTERVAL \"" . $my_interval . " " . $end_time . ":02\" DAY_SECOND ," . $is_appr . " ),"; // FixIn: 10.0.0.51.
201 - }
202 - }
203 - $wp_queries_sub = substr($wp_queries_sub,0,-1) . ";";
204 -
205 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
206 - $wpdb->query( $wp_queries_sub );
207 - }
208 - }
209 - } else if ( $version == 'free' ) {
210 - if (empty($my_bk_types)) $my_bk_types=array(1,1);
211 - else shuffle($my_bk_types);
212 -
213 - for ($i = 0; $i < count($my_bk_types); $i++) {
214 -
215 - $bk_type = 1;
216 - $is_appr = wp_rand( 0, 1 );
217 - $evry_one = 2;
218 - if ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( ( 'beta' === $_SERVER['HTTP_HOST'] ) || ( 'freetest.wpbookingcalendar.com' === $_SERVER['HTTP_HOST'] ) ) ) {
219 - $evry_one = wp_rand( 1, 21 );
220 - $num_days = wp_rand( 1, 10 );
221 - $days_start_shift = - 1 * wp_rand( 0, 28 );
222 - }
223 -
224 -
225 - $second_name = wpbc_get_initial_values_4_demo('second_name');
226 - $form = '';
227 - $form .= 'text^name'.$bk_type.'^'.wpbc_get_initial_values_4_demo('name').'~';
228 - $form .= 'text^secondname'.$bk_type.'^'.$second_name.'~';
229 - $form .= 'text^email'.$bk_type.'^'.$second_name.'[email protected]~';
230 - $form .= 'text^phone'.$bk_type.'^'.wpbc_get_initial_values_4_demo('phone').'~';
231 - $form .= 'textarea^details'.$bk_type.'^'.wpbc_get_initial_values_4_demo('info');
232 -
233 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date ) VALUES ( '".$form."', NOW() ) ;";
234 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
235 - $wpdb->query( $wp_bk_querie );
236 - $temp_id = $wpdb->insert_id;
237 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
238 - booking_id,
239 - booking_date,
240 - approved
241 - ) VALUES ";
242 -
243 - if ( ( 'beta' === $_SERVER['HTTP_HOST'] ) || ( 'freetest.wpbookingcalendar.com' === $_SERVER['HTTP_HOST'] ) ) {
244 - for ($d_num = 0; $d_num < $num_days; $d_num++) {
245 - $wp_queries_sub .= "( ". $temp_id .", CURDATE()+ INTERVAL ".($days_start_shift + 2*($i+1)*$evry_one + $d_num)." day ,". $is_appr." ),";
246 - }
247 - $wp_queries_sub = substr($wp_queries_sub,0,-1) . ";";
248 - } else {
249 - $wp_queries_sub .= "( ". $temp_id .", CURDATE()+ INTERVAL ".(2*($i+1)*$evry_one+2)." day ,". $is_appr." ),
250 - ( ". $temp_id .", CURDATE()+ INTERVAL ".(2*($i+1)*$evry_one+3)." day ,". $is_appr." ),
251 - ( ". $temp_id .", CURDATE()+ INTERVAL ".(2*($i+1)*$evry_one+4)." day ,". $is_appr." );";
252 - }
253 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
254 - $wpdb->query( $wp_queries_sub );
255 - }
256 - } else if ( $version == 'personal' ) {
257 - $max_num_bookings = 8; // How many bookings exist
258 - for ($i = 0; $i < $max_num_bookings; $i++) {
259 -
260 - $bk_type = wp_rand(1,4); // Booking Resource
261 - $min_days = 1;
262 - $max_days = 7;
263 - $is_appr = wp_rand(0,1); // Pending | Approved
264 - $evry_one = $max_days; // Multiplier of interval between 2 dates of different bookings
265 - $num_days = wp_rand($min_days,$max_days); // Max Number of Dates for specific booking
266 - $days_start_shift = -1 * (ceil($max_num_bookings/2)) * $max_days; // How long far ago we are start bookings
267 -
268 - $second_name = wpbc_get_initial_values_4_demo('second_name');
269 - $form = '';
270 - $form .= 'text^name'.$bk_type.'^'.wpbc_get_initial_values_4_demo('name').'~';
271 - $form .= 'text^secondname'.$bk_type.'^'.$second_name.'~';
272 - $form .= 'text^email'.$bk_type.'^'.$second_name.'[email protected]~';
273 - $form .= 'text^phone'.$bk_type.'^'.wpbc_get_initial_values_4_demo('phone').'~';
274 - $form .= 'selectbox-one^visitors'.$bk_type.'^'.wp_rand(1,4).'~';
275 - $form .= 'selectbox-one^children'.$bk_type.'^'.wp_rand(0,3).'~';
276 - $form .= 'textarea^details'.$bk_type.'^'.wpbc_get_initial_values_4_demo('info');
277 -
278 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, booking_type, hash, modification_date ) VALUES
279 - ( '".$form."', ".$bk_type .", MD5('". time() . '_' . wp_rand(1000,1000000)."'), NOW() ) ;";
280 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
281 - $wpdb->query( $wp_bk_querie );
282 - $temp_id = $wpdb->insert_id;
283 -
284 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
285 - booking_id,
286 - booking_date,
287 - approved
288 - ) VALUES ";
289 - for ($d_num = 0; $d_num < $num_days; $d_num++) {
290 - $wp_queries_sub .= "( ". $temp_id .", CURDATE()+ INTERVAL ".($days_start_shift + $i*$evry_one + $d_num)." day ,". $is_appr." ),";
291 - }
292 - $wp_queries_sub = substr($wp_queries_sub,0,-1) . ";";
293 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
294 - $wpdb->query( $wp_queries_sub );
295 - }
296 - } else if ( $version == 'biz_s' ) {
297 - $max_num_bookings = 8; // How many bookings exist
298 - for ($i = 0; $i < $max_num_bookings; $i++) {
299 -
300 - $bk_type = wp_rand(1,4); // Booking Resource
301 - $min_days = 1;
302 - $max_days = 1;
303 - $is_appr = wp_rand(0,1); // Pending | Approved
304 - $evry_one = $max_days; // Multiplier of interval between 2 dates of different bookings
305 - $num_days = wp_rand($min_days,$max_days); // Max Number of Dates for specific booking
306 - $days_start_shift = (ceil($max_num_bookings/4)) * $max_days; // How long far ago we are start bookings
307 -
308 - $second_name = wpbc_get_initial_values_4_demo('second_name');
309 - $city = wpbc_get_initial_values_4_demo('city');
310 - $range_time = wpbc_get_initial_values_4_demo('rangetime');
311 - $start_time = $range_time[0];
312 - $end_time = $range_time[1];
313 -
314 - $form = '';
315 - $form .= 'selectbox-one^rangetime'.$bk_type.'^'.$start_time.' - '.$end_time.'~';
316 - $form .= 'text^name'.$bk_type.'^'.wpbc_get_initial_values_4_demo('name').'~';
317 - $form .= 'text^secondname'.$bk_type.'^'.$second_name.'~';
318 - $form .= 'text^email'.$bk_type.'^'.$second_name.'[email protected]~';
319 - $form .= 'text^address'.$bk_type.'^'.wpbc_get_initial_values_4_demo('adress').'~';
320 - $form .= 'text^city'.$bk_type.'^'.$city[0].'~';
321 - $form .= 'text^postcode'.$bk_type.'^'.wpbc_get_initial_values_4_demo('postcode').'~';
322 - $form .= 'text^country'.$bk_type.'^'.$city[1].'~';
323 - $form .= 'text^phone'.$bk_type.'^'.wpbc_get_initial_values_4_demo('phone').'~';
324 - $form .= 'selectbox-one^visitors'.$bk_type.'^'.wp_rand(1,4).'~';
325 - $form .= 'checkbox^children'.$bk_type.'[]^'.wp_rand(0,3).'~';
326 - $form .= 'textarea^details'.$bk_type.'^'.wpbc_get_initial_values_4_demo('info');
327 -
328 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, booking_type, cost, hash, modification_date ) VALUES
329 - ( '".$form."', ".$bk_type .", ".wp_rand(0,1000).", MD5('". time() . '_' . wp_rand(1000,1000000)."'), NOW() ) ;";
330 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
331 - $wpdb->query( $wp_bk_querie );
332 - $temp_id = $wpdb->insert_id;
333 -
334 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
335 - booking_id,
336 - booking_date,
337 - approved
338 - ) VALUES ";
339 - for ($d_num = 0; $d_num < $num_days; $d_num++) {
340 - $my_interval = ( $i*$evry_one + $d_num);
341 -// $wp_queries_sub .= "( ". $temp_id .", CURDATE()+ INTERVAL \"".($days_start_shift + $i*$evry_one + $d_num)." ".$start_time.":01\" DAY_SECOND ,". $is_appr." ),";
342 -// $wp_queries_sub .= "( ". $temp_id .", CURDATE()+ INTERVAL \"".($days_start_shift + $i*$evry_one + $d_num)." ".$end_time .":02\" DAY_SECOND ,". $is_appr." ),";
343 - $wp_queries_sub .= "( ". $temp_id .", DATE_ADD(CURDATE(), INTERVAL -".$days_start_shift." DAY) + INTERVAL \"".$my_interval." ".$start_time.":01\" DAY_SECOND ,". $is_appr." ),";
344 - $wp_queries_sub .= "( ". $temp_id .", DATE_ADD(CURDATE(), INTERVAL -".$days_start_shift." DAY) + INTERVAL \"".$my_interval." ".$end_time.":02\" DAY_SECOND ,". $is_appr." ),";
345 - }
346 - $wp_queries_sub = substr($wp_queries_sub,0,-1) . ";";
347 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
348 - $wpdb->query( $wp_queries_sub );
349 - }
350 - } else if ( $version == 'biz_m' ) {
351 - $max_num_bookings = 8; // How many bookings exist
352 - for ($i = 0; $i < $max_num_bookings; $i++) {
353 -
354 - $bk_type = wp_rand(1,4); // Booking Resource
355 - $min_days = 3;
356 - $max_days = 7;
357 - $is_appr = wp_rand(0,1); // Pending | Approved
358 - $evry_one = $max_days; // Multiplier of interval between 2 dates of different bookings
359 - $num_days = wp_rand($min_days,$max_days); // Max Number of Dates for specific booking
360 - $days_start_shift = (ceil($max_num_bookings/2)) * $max_days; // How long far ago we are start bookings
361 -
362 - $second_name = wpbc_get_initial_values_4_demo('second_name');
363 - $city = wpbc_get_initial_values_4_demo('city');
364 - $start_time = '14:00';
365 - $end_time = '12:00';
366 -
367 - $form = '';
368 - $form .= 'text^name'.$bk_type.'^'.wpbc_get_initial_values_4_demo('name').'~';
369 - $form .= 'text^secondname'.$bk_type.'^'.$second_name.'~';
370 - $form .= 'text^email'.$bk_type.'^'.$second_name.'[email protected]~';
371 - $form .= 'text^address'.$bk_type.'^'.wpbc_get_initial_values_4_demo('adress').'~';
372 - $form .= 'text^city'.$bk_type.'^'.$city[0].'~';
373 - $form .= 'text^postcode'.$bk_type.'^'.wpbc_get_initial_values_4_demo('postcode').'~';
374 - $form .= 'text^country'.$bk_type.'^'.$city[1].'~';
375 - $form .= 'text^phone'.$bk_type.'^'.wpbc_get_initial_values_4_demo('phone').'~';
376 - $form .= 'selectbox-one^visitors'.$bk_type.'^'.wp_rand(1,4).'~';
377 - $form .= 'checkbox^children'.$bk_type.'[]^'.wp_rand(0,3).'~';
378 - $form .= 'textarea^details'.$bk_type.'^'.wpbc_get_initial_values_4_demo('info').'~';
379 - $form .= 'text^starttime'.$bk_type.'^'.$start_time.'~';
380 - $form .= 'text^endtime'.$bk_type.'^'.$end_time;
381 -
382 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, booking_type, cost, hash, modification_date ) VALUES
383 - ( '".$form."', ".$bk_type .", ".wp_rand(0,1000).", MD5('". time() . '_' . wp_rand(1000,1000000)."'), NOW() ) ;";
384 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
385 - $wpdb->query( $wp_bk_querie );
386 - $temp_id = $wpdb->insert_id;
387 -
388 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
389 - booking_id,
390 - booking_date,
391 - approved
392 - ) VALUES ";
393 - for ($d_num = 0; $d_num < $num_days; $d_num++) {
394 - $my_interval = ( $i*$evry_one + $d_num);
395 - if ($d_num == 0) { // Check In
396 - $wp_queries_sub .= "( ". $temp_id .", DATE_ADD(CURDATE(), INTERVAL -".$days_start_shift." day) + INTERVAL \"".$my_interval." ".$start_time.":01\" DAY_SECOND ,". $is_appr." ),";
397 - } elseif ($d_num == ($num_days-1) ) { // Check Out
398 - $wp_queries_sub .= "( ". $temp_id .", DATE_ADD(CURDATE(), INTERVAL -".$days_start_shift." day) + INTERVAL \"".$my_interval." ".$end_time.":02\" DAY_SECOND ,". $is_appr." ),";
399 - } else {
400 - $wp_queries_sub .= "( ". $temp_id .", DATE_ADD(CURDATE(), INTERVAL -".$days_start_shift." day) + INTERVAL ".$my_interval." day ,". $is_appr." ),";
401 - }
402 - }
403 - $wp_queries_sub = substr($wp_queries_sub,0,-1) . ";";
404 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
405 - $wpdb->query( $wp_queries_sub );
406 - }
407 -
408 - } else if ( $version == 'biz_l' ) {
409 - $max_num_bookings = 12; // How many bookings exist
410 - for ($res_groups = 0; $res_groups < 2; $res_groups++)
411 - for ($i = 0; $i < $max_num_bookings; $i++) {
412 - if($res_groups)
413 - $bk_type = wp_rand(1,6); // Booking Resource
414 - else $bk_type = wp_rand(7,12); // Booking Resource
415 - $min_days = 2;
416 - $max_days = 7;
417 - $is_appr = wp_rand(0,1); // Pending | Approved
418 - $evry_one = $max_days; // Multiplier of interval between 2 dates of different bookings
419 - $num_days = wp_rand($min_days,$max_days); // Max Number of Dates for specific booking
420 - $days_start_shift = (ceil($max_num_bookings/2)) * $max_days; // How long far ago we are start bookings
421 -
422 - $second_name = wpbc_get_initial_values_4_demo('second_name');
423 - $city = wpbc_get_initial_values_4_demo('city');
424 - $start_time = '14:00';
425 - $end_time = '12:00';
426 -
427 -
428 - $form = '';
429 - $form .= 'text^name'.$bk_type.'^'.wpbc_get_initial_values_4_demo('name').'~';
430 - $form .= 'text^secondname'.$bk_type.'^'.$second_name.'~';
431 - $form .= 'text^email'.$bk_type.'^'.$second_name.'[email protected]~';
432 - $form .= 'text^address'.$bk_type.'^'.wpbc_get_initial_values_4_demo('adress').'~';
433 - $form .= 'text^city'.$bk_type.'^'.$city[0].'~';
434 - $form .= 'text^postcode'.$bk_type.'^'.wpbc_get_initial_values_4_demo('postcode').'~';
435 - $form .= 'text^country'.$bk_type.'^'.$city[1].'~';
436 - $form .= 'text^phone'.$bk_type.'^'.wpbc_get_initial_values_4_demo('phone').'~';
437 - $form .= 'selectbox-one^visitors'.$bk_type.'^1~';
438 - //$form .= 'checkbox^children'.$bk_type.'[]^0~';
439 - $form .= 'textarea^details'.$bk_type.'^'.wpbc_get_initial_values_4_demo('info').'~';
440 - $form .= 'coupon^coupon'.$bk_type.'^ ';
441 -
442 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, booking_type, cost, hash, modification_date ) VALUES
443 - ( '".$form."', ".$bk_type .", ".wp_rand(0,1000).", MD5('". time() . '_' . wp_rand(1000,1000000)."'), NOW() ) ;";
444 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
445 - $wpdb->query( $wp_bk_querie );
446 - $temp_id = $wpdb->insert_id;
447 -
448 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
449 - booking_id,
450 - booking_date,
451 - approved
452 - ) VALUES ";
453 - for ($d_num = 0; $d_num < $num_days; $d_num++) {
454 - $my_interval = ( $i*$evry_one + $d_num);
455 -
456 - $wp_queries_sub .= "( ". $temp_id .", DATE_ADD(CURDATE(), INTERVAL -".$days_start_shift." day) + INTERVAL ".$my_interval." day ,". $is_appr." ),";
457 - }
458 - $wp_queries_sub = substr($wp_queries_sub,0,-1) . ";";
459 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
460 - $wpdb->query( $wp_queries_sub );
461 - }
462 - }
463 140 }
464 141
465 142
466 -function wpbc_get_initial_values_4_demo( $type ) {
467 - $names = array('Jacob', 'Michael', 'Daniel', 'Anthony', 'William', 'Emma', 'Sophia', 'Kamila', 'Isabella', 'Jack', 'Daniel', 'Matthew',
468 - 'Olivia', 'Emily', 'Grace', 'Jessica', 'Joshua', 'Harry', 'Thomas', 'Oliver', 'Jack' );
469 - $second_names = array( 'Smith', 'Johnson', 'Widams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriguez', 'Wilyson', 'Gonzalez', 'Gomez',
470 - 'Taylor', 'Bron', 'Wilson', 'Davies', 'Robinson', 'Evans', 'Walker', 'Jackson', 'Clarke' );
471 - $city = array( 'New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'San Antonio', 'San Diego', 'San Jose', 'Detroit',
472 - 'San Francisco', 'Jacksonville', 'Austin',
473 - 'London', 'Birmingham', 'Leeds', 'Glasgow', 'Sheffield', 'Bradford', 'Edinburgh', 'Liverpool', 'Manchester' );
474 - $adress = array('30 Mortensen Avenue', '144 Hitchcock Rd', '222 Lincoln Ave', '200 Lincoln Ave', '65 West Alisal St',
475 - '426 Work St', '65 West Alisal Street', '159 Main St', '305 Jonoton Avenue', '423 Caiptown Rd', '34 Linoro Ave',
476 - '50 Voro Ave', '15 East St', '226 Middle St', '35 West Town Street', '59 Other St', '50 Merci Ave', '15 Dolof St',
477 - '226 Gordon St', '35 Sero Street', '59 Exit St' );
478 - $country = array( 'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'UK','UK','UK','UK','UK','UK','UK','UK','UK' );
479 143
480 - $range_times = array( array("10:00","12:00"), array("12:00","14:00"), array("14:00","16:00"), array("16:00","18:00"), array("18:00","20:00") );
481 144
482 - switch ($type) {
483 - case 'rangetime':
484 - return $range_times[ wp_rand(0 , (count($range_times)-1) ) ] ;
485 - break;
486 - case 'name':
487 - return $names[ wp_rand(0 , (count($names)-1) ) ] ;
488 - break;
489 - case 'second_name':
490 - return $second_names[ wp_rand(0 , (count($second_names)-1) ) ] ;
491 - break;
492 - case 'adress':
493 - return $adress[ wp_rand(0 , (count($adress)-1) ) ] ;
494 - break;
495 - case 'city':
496 - $city_num = wp_rand(0 , (count($city)-1) ) ;
497 - return array( $city[$city_num], $country[$city_num]) ;
498 - break;
499 - case 'postcode':
500 - return (wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).wp_rand(0,9));
501 - break;
502 - case 'phone':
503 - return (wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).'-'.wp_rand(0,9).wp_rand(0,9).'-'.wp_rand(0,9).wp_rand(0,9)) ;
504 - break;
505 - case 'starttime':
506 - return ('0'.wp_rand(0,9) . ':' .wp_rand(1,3).'0' );
507 - break;
508 - case 'endtime':
509 - return (wp_rand(12,23) . ':' .wp_rand(1,3).'0' );
510 - break;
511 - case 'visitors':
512 - return wp_rand(1,4);
513 - break;
514 - default:
515 - return '';
516 - break;
517 - }
518 -
519 -}
520 -
521 -
522 -function wpbc_set_default_initial_values( $evry_one = 1 ) {
523 - global $wpdb;
524 - $names = array( 'Jacob', 'Michael', 'Daniel', 'Anthony', 'William', 'Emma', 'Sophia', 'Kamila', 'Isabella', 'Jack', 'Daniel', 'Matthew',
525 - 'Olivia', 'Emily', 'Grace', 'Jessica', 'Joshua', 'Harry', 'Thomas', 'Oliver', 'Jack' );
526 - $second_names = array( 'Smith', 'Johnson', 'Widams', 'Brown', 'Jones', 'Miller', 'Davis', 'Garcia', 'Rodriguez', 'Wilyson', 'Gonzalez', 'Gomez',
527 - 'Taylor', 'Bron', 'Wilson', 'Davies', 'Robinson', 'Evans', 'Walker', 'Jackson', 'Clarke' );
528 - $city = array( 'New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'San Antonio', 'San Diego', 'San Jose', 'Detroit',
529 - 'San Francisco', 'Jacksonville', 'Austin',
530 - 'London', 'Birmingham', 'Leeds', 'Glasgow', 'Sheffield', 'Bradford', 'Edinburgh', 'Liverpool', 'Manchester' );
531 - $adress = array( '30 Mortensen Avenue', '144 Hitchcock Rd', '222 Lincoln Ave', '200 Lincoln Ave', '65 West Alisal St',
532 - '426 Work St', '65 West Alisal Street', '159 Main St', '305 Jonoton Avenue', '423 Caiptown Rd', '34 Linoro Ave',
533 - '50 Voro Ave', '15 East St', '226 Middle St', '35 West Town Street', '59 Other St', '50 Merci Ave', '15 Dolof St',
534 - '226 Gordon St', '35 Sero Street', '59 Exit St' );
535 - $country = array( 'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'US' ,'UK','UK','UK','UK','UK','UK','UK','UK','UK' );
536 - $info = array( ' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ' ,' ',' ',' ',' ',' ',' ',' ',' ',' ' );
537 -
538 - for ($i = 0; $i < count($names); $i++) {
539 - if ( ($i % $evry_one) !==0 ) {
540 - continue;
541 - }
542 - $bk_type = wp_rand(1,4);
543 - $is_appr = wp_rand(0,1);
544 -
545 - $start_time = '0'.wp_rand(0,9) . ':' .wp_rand(1,3).'0' ;
546 - $end_time = wp_rand(12,23) . ':' .wp_rand(1,3).'0' ;
547 -
548 - $form = 'text^starttime'.$bk_type.'^'.$start_time.'~';
549 - $form .='text^endtime'.$bk_type.'^'.$end_time.'~';
550 - $form .='text^name'.$bk_type.'^'.$names[$i].'~';
551 - $form .='text^secondname'.$bk_type.'^'.$second_names[$i].'~';
552 - $form .='text^email'.$bk_type.'^'.$second_names[$i].'[email protected]~';
553 - $form .='text^address'.$bk_type.'^'.$adress[$i].'~';
554 - $form .='text^city'.$bk_type.'^'.$city[$i].'~';
555 - $form .='text^postcode'.$bk_type.'^'.wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).'~';
556 - $form .='text^country'.$bk_type.'^'.$country[$i].'~';
557 - $form .='text^phone'.$bk_type.'^'.wp_rand(0,9).wp_rand(0,9).wp_rand(0,9).'-'.wp_rand(0,9).wp_rand(0,9).'-'.wp_rand(0,9).wp_rand(0,9).'~';
558 - $form .='selectbox-one^visitors'.$bk_type.'^'.wp_rand(0,9).'~';
559 - $form .='checkbox^children'.$bk_type.'[]^false~';
560 - $form .='textarea^details'.$bk_type.'^'.$info[$i];
561 -
562 - $wp_bk_querie = "INSERT INTO {$wpdb->prefix}booking ( form, booking_type, cost, hash ) VALUES
563 - ( '".$form."', ".$bk_type .", ".wp_rand(0,1000).", MD5('". time() . '_' . wp_rand(1000,1000000)."') ) ;";
564 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
565 - $wpdb->query( $wp_bk_querie );
566 -
567 - $temp_id = $wpdb->insert_id;
568 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
569 - booking_id,
570 - booking_date,
571 - approved
572 - ) VALUES
573 - ( ". $temp_id .", CURDATE()+ INTERVAL \"".(2*($i+1)*$evry_one+2)." ".$start_time.":01"."\" DAY_SECOND ,". $is_appr." ),
574 - ( ". $temp_id .", CURDATE()+ INTERVAL ".(2*($i+1)*$evry_one+3)." day ,". $is_appr." ),
575 - ( ". $temp_id .", CURDATE()+ INTERVAL \"".(2*($i+1)*$evry_one+4)." ".$end_time.":02"."\" DAY_SECOND ,". $is_appr." );";
576 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
577 - $wpdb->query( $wp_queries_sub );
578 - }
579 -}
580 -
581 -// </editor-fold>
582 -
583 -
584 145 // <editor-fold defaultstate="collapsed" desc=" Support & Maintence " >
585 146
586 147 /** Reindex DataBase to have "date key field" for be able to sort by dates. */
587 148 function wpbc_reindex_booking_db(){ global $wpdb;
@@ -607,10 +168,10 @@
607 168 <?php
608 169 }
609 170
610 171 if (wpbc_is_field_in_table_exists('booking','sort_date') == 0) {
611 - $simple_sql = "ALTER TABLE {$wpdb->prefix}booking ADD sort_date datetime AFTER booking_id";
612 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
172 + $simple_sql = "ALTER TABLE {$wpdb->prefix}booking ADD COLUMN sort_date datetime"; // FixIn: 10.12.1.5.
173 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
613 174 $wpdb->query( $simple_sql );
614 175 }
615 176
616 177 // Refill the sort date index.
@@ -616,15 +177,15 @@
616 177 // Refill the sort date index.
617 178 if (wpbc_is_field_in_table_exists('booking','sort_date') != 0) {
618 179
619 180 $bookings_res = array();
620 - if ( ! wpbc_is_this_wp_playground_db() ) { // FixIn: 10.0.0.1.
181 +
621 182 // 1. Select all bookings ID, where sort_date is NULL in wp_booking.
622 183 $sql = " SELECT booking_id as id FROM {$wpdb->prefix}booking as bk WHERE sort_date IS NULL";
623 184
624 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
185 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
625 186 $bookings_res = $wpdb->get_results( $sql );
626 - }
187 +
627 188 if ( $is_show_messages ) {
628 189 /* translators: 1: ... */
629 190 echo esc_html( sprintf( __( '%1$s Found %2$s not indexed bookings %3$s', 'booking' ), ' ', count( $bookings_res ), '<br/>' ) );
630 191 }
@@ -639,9 +200,9 @@
639 200 $sql = " SELECT booking_id as id, booking_date as date" ;
640 201 $sql .= " FROM {$wpdb->prefix}bookingdates as bdt" ;
641 202 $sql .= " WHERE booking_id IN ( ". $id_string ." ) GROUP BY bdt.booking_id ORDER BY bdt.booking_date " ;
642 203
643 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
204 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
644 205 $sort_date_array = $wpdb->get_results( $sql );
645 206
646 207 if ( $is_show_messages ) {
647 208 /* translators: 1: ... */
@@ -650,11 +211,11 @@
650 211
651 212 //3. Insert that firtst date into the bookings in wp_booking
652 213 $ii=0;
653 214 foreach ($sort_date_array as $value) { $ii++;
654 - $sql = "UPDATE {$wpdb->prefix}booking as bdt ";
215 + $sql = "UPDATE {$wpdb->prefix}booking ";
655 216 $sql .= " SET sort_date = '".$value->date. "' WHERE booking_id = ". $value->id . " ";
656 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
217 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
657 218 $wpdb->query( $sql );
658 219
659 220 if ( $is_show_messages ) {
660 221 /* translators: 1: ... */
@@ -676,13 +237,17 @@
676 237 // A c t i v a t e & D e a c t i v a t e
677 238 ////////////////////////////////////////////////////////////////////////////////
678 239
679 240 /** Activation */
680 -function wpbc_booking_activate() {
681 -
241 +function wpbc_booking_activate() {
242 +
243 + wpbc_load_translation();
244 +
245 + $is_new_install = wpbc_is_plugin_initial_install();
246 +
682 247 make_bk_action( 'wpbc_before_activation' );
683 248
684 - wpbc_load_translation();
249 +
685 250
686 251 $version = wpbc_get_plugin_version_type();
687 252 $is_demo = wpbc_is_this_demo();
688 253
@@ -688,10 +253,20 @@
688 253
689 254 // -----------------------------------------------------------------------------------------------------------------
690 255 // Options
691 256 // -----------------------------------------------------------------------------------------------------------------
692 - $default_options_to_add = wpbc_get_default_options();
693 -
257 + $default_options_to_add = wpbc_get_default_options();
258 + // Existing installations retain their saved value; add_bk_option() never overwrites it during upgrades.
259 + if ( $is_new_install ) {
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 + }
267 + }
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.
694 269 make_bk_action( 'wpbc_before_activation__add_options', $default_options_to_add ); // FixIn: 9.6.2.11.
695 270
696 271 foreach ( $default_options_to_add as $default_option_name => $default_option_value ) {
697 272 add_bk_option( $default_option_name, $default_option_value );
@@ -701,94 +276,148 @@
701 276 // -----------------------------------------------------------------------------------------------------------------
702 277 // DB Tables
703 278 // -----------------------------------------------------------------------------------------------------------------
704 279 if ( true ){
705 - global $wpdb;
706 - $charset_collate = '';
707 - //if ( $wpdb->has_cap( 'collation' ) ) {
708 - if ( ! empty($wpdb->charset) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
709 - if ( ! empty($wpdb->collate) ) $charset_collate .= " COLLATE $wpdb->collate";
710 - //}
711 280
712 - $wp_queries = array();
713 - if ( ! wpbc_is_table_exists('booking') ) { // Check if tables not exist yet
714 -// FixIn: 10.0.0.1.
715 - $simple_sql = "CREATE TABLE {$wpdb->prefix}booking (
716 - booking_id bigint(20) unsigned NOT NULL auto_increment, " .
717 - /*
718 - " booking_options TEXT,
719 - trash bigint(10) NOT NULL default 0,
720 - is_new bigint(10) NOT NULL default 1,
721 - sort_date datetime,
722 - modification_date datetime,
723 - creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
724 - status varchar(200) NOT NULL default '',
725 - sync_gid varchar(200) NOT NULL default '',
726 - is_trash datetime,
727 - hash TEXT, " . /**/
281 + global $wpdb;
728 282
729 - " form text ,
730 - booking_type bigint(10) NOT NULL default 1,
731 - PRIMARY KEY (booking_id)
732 - ) {$charset_collate};";
733 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
734 - $wpdb->query( $simple_sql );
735 - } elseif (wpbc_is_field_in_table_exists('booking','form') == 0) {
736 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD form TEXT AFTER booking_id";
737 - }
283 + // ----------------------------------------------------------------------------
284 + // Charset / Collation
285 + // ----------------------------------------------------------------------------
286 + $charset_collate = '';
287 + if ( ! empty( $wpdb->charset ) ) {
288 + $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
289 + }
290 + if ( ! empty( $wpdb->collate ) ) {
291 + $charset_collate .= " COLLATE {$wpdb->collate}";
292 + }
738 293
739 - if (wpbc_is_field_in_table_exists('booking','modification_date') == 0) {
740 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD modification_date datetime AFTER booking_id";
741 - }
294 + // ----------------------------------------------------------------------------
295 + // Table name
296 + // ----------------------------------------------------------------------------
297 + $table_name = $wpdb->prefix . 'booking';
742 298
743 - // FixIn: 9.2.3.3.
744 - if ( wpbc_is_field_in_table_exists( 'booking', 'creation_date' ) == 0 ) {
745 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER modification_date";
746 - /**
747 - *
748 - // Can be only one 'TIMESTAMP' field at some servers.
749 - // ADD re_create_date TIMESTAMP NOT NULL DEFAULT 0 AFTER rules_id
750 - //$wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER booking_id";
751 - */
752 - }
299 + // ----------------------------------------------------------------------------
300 + // Queries queue for upgrades only
301 + // ----------------------------------------------------------------------------
302 + $wp_queries = array();
753 303
754 - if (wpbc_is_field_in_table_exists('booking','sort_date') == 0) {
755 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD sort_date datetime AFTER booking_id";
756 - }
304 + // ----------------------------------------------------------------------------
305 + // 1) First install: CREATE booking TABLE.
306 + // ----------------------------------------------------------------------------
307 + if ( ! wpbc_is_table_exists( 'booking' ) ) {
757 308
758 - if (wpbc_is_field_in_table_exists('booking','status') == 0) {
759 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD status varchar(200) NOT NULL default '' AFTER booking_id";
760 - }
309 + $create_sql = "CREATE TABLE {$table_name} (
310 + booking_id bigint(20) unsigned NOT NULL auto_increment,
311 + booking_type bigint(10) NOT NULL default 1,
761 312
762 - if (wpbc_is_field_in_table_exists('booking','is_new') == 0) {
763 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD is_new bigint(10) NOT NULL default 1 AFTER booking_id";
764 - }
313 + form TEXT,
314 + hash TEXT,
315 + booking_options TEXT,
316 + status varchar(200) NOT NULL default '',
317 +
318 + is_new bigint(10) NOT NULL default 1,
319 + sync_gid varchar(200) NOT NULL default '',
320 + trash bigint(10) NOT NULL default 0,
321 + is_trash datetime,
322 +
323 + sort_date datetime,
324 + modification_date datetime,
325 + creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
326 +
327 + PRIMARY KEY (booking_id)
328 + ) {$charset_collate};";
765 329
766 - // Version: 5.2 - Google ID of the booking for Sync functionality
767 - if (wpbc_is_field_in_table_exists('booking','sync_gid') == 0) {
768 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD sync_gid varchar(200) NOT NULL default '' AFTER booking_id";
769 - }
330 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
331 + $wpdb->query( $create_sql );
770 332
771 - // FixIn: 9.2.3.5.
772 - if (wpbc_is_field_in_table_exists('booking','is_trash') == 0) {
773 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD is_trash datetime AFTER booking_id";
774 - }
333 + // ----------------------------------------------------------------------------
334 + // 2) Upgrade path: only add missing columns (your current logic)
335 + // ----------------------------------------------------------------------------
336 + } else {
775 337
776 - // FixIn: 6.1.1.10.
777 - if (wpbc_is_field_in_table_exists('booking','trash') == 0) {
778 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD trash bigint(10) NOT NULL default 0 AFTER booking_id";
779 - }
338 + if ( wpbc_is_field_in_table_exists( 'booking', 'form' ) == 0 ) {
339 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN form TEXT";
340 + }
780 341
342 + if ( wpbc_is_field_in_table_exists( 'booking', 'modification_date' ) == 0 ) {
343 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN modification_date datetime";
344 + }
781 345
346 + // FixIn: 9.2.3.3.
347 + if ( wpbc_is_field_in_table_exists( 'booking', 'creation_date' ) == 0 ) {
348 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
349 + }
782 350
783 - // FixIn: 9.1.2.12.
784 - if ( wpbc_is_field_in_table_exists( 'booking', 'booking_options' ) == 0 ) {
785 - $wp_queries[] = "ALTER TABLE {$wpdb->prefix}booking ADD booking_options TEXT AFTER booking_id";
786 - }
351 + if ( wpbc_is_field_in_table_exists( 'booking', 'sort_date' ) == 0 ) {
352 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN sort_date datetime";
353 + }
787 354
788 - // FixIn: 8.7.9.1.
789 - if ( ! wpbc_is_table_exists('bookingdates') ) { // Check if tables not exist yet
790 - $simple_sql = "CREATE TABLE {$wpdb->prefix}bookingdates (
355 + if ( wpbc_is_field_in_table_exists( 'booking', 'status' ) == 0 ) {
356 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN status varchar(200) NOT NULL default ''";
357 + }
358 +
359 + if ( wpbc_is_field_in_table_exists( 'booking', 'is_new' ) == 0 ) {
360 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN is_new bigint(10) NOT NULL default 1";
361 + }
362 +
363 + // Version: 5.2 - Google ID for Sync
364 + if ( wpbc_is_field_in_table_exists( 'booking', 'sync_gid' ) == 0 ) {
365 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN sync_gid varchar(200) NOT NULL default ''";
366 + }
367 +
368 + // FixIn: 9.2.3.5.
369 + if ( wpbc_is_field_in_table_exists( 'booking', 'is_trash' ) == 0 ) {
370 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN is_trash datetime";
371 + }
372 +
373 + // FixIn: 6.1.1.10.
374 + if ( wpbc_is_field_in_table_exists( 'booking', 'trash' ) == 0 ) {
375 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN trash bigint(10) NOT NULL default 0";
376 + }
377 +
378 + // FixIn: 9.1.2.12.
379 + if ( wpbc_is_field_in_table_exists( 'booking', 'booking_options' ) == 0 ) {
380 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN booking_options TEXT";
381 + }
382 +
383 + if ( wpbc_is_field_in_table_exists( 'booking', 'hash' ) == 0 ) {
384 + $wp_queries[] = "ALTER TABLE {$table_name} ADD COLUMN hash TEXT";
385 +
386 + // Update hash value only in last 100 bookings.
387 + $sql_check_table = "SELECT booking_id as id FROM {$wpdb->prefix}booking ORDER BY booking_id DESC LIMIT 0, 100";
388 +
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
390 + foreach ( $res as $l ) {
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
396 + }
397 + }
398 + }
399 +
400 + // ----------------------------------------------------------------------------
401 + // Execute queued upgrade queries (only runs on upgrades, not new install)
402 + // ----------------------------------------------------------------------------
403 + if ( ! empty( $wp_queries ) ) {
404 + foreach ( $wp_queries as $sql ) {
405 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
406 + $wpdb->query( $sql );
407 + }
408 + }
409 +
410 +
411 + $is_insert_test_bookings = false;
412 +
413 + // ----------------------------------------------------------------------------
414 + // 2. Install: CREATE bookingdate TABLE.
415 + // ----------------------------------------------------------------------------
416 +
417 + if ( ! wpbc_is_table_exists( 'bookingdates' ) ) {
418 + // Check if tables not exist yet.
419 + $simple_sql = "CREATE TABLE {$wpdb->prefix}bookingdates (
791 420 booking_dates_id bigint(20) unsigned NOT NULL auto_increment,
792 421 booking_id bigint(20) unsigned NOT NULL,
793 422 booking_date datetime NOT NULL default '0000-00-00 00:00:00',
794 423 approved bigint(20) unsigned NOT NULL default 0,
@@ -794,125 +423,182 @@
794 423 approved bigint(20) unsigned NOT NULL default 0,
795 424 PRIMARY KEY (booking_dates_id)
796 425 ) {$charset_collate}";
797 426
798 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
427 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
799 428 $wpdb->query( $simple_sql );
800 429
801 - if( ! class_exists( 'wpdev_bk_personal' ) ) {
802 - $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date ) VALUES (
803 - 'text^name1^Jony~text^secondname1^Smith~text^email1^[email protected]~text^phone1^458-77-77~textarea^details1^Reserve a room with sea view', NOW() );";
804 - }
805 - }
430 + if ( ! class_exists( 'wpdev_bk_personal' ) ) {
431 + $is_insert_test_bookings = true;
432 + }
433 + }
806 434
807 -
808 - // If we remove this index, so then its can significant impact to the speed of page loading at the Booking Listing and Timelines.
809 - /**
810 - (
811 - [0] => SELECT * FROM wp_booking as bk WHERE EXISTS (
812 - SELECT *
813 - FROM wp_bookingdates as dt
814 - WHERE bk.booking_id = dt.booking_id AND ( dt.booking_date >= '2016-11-01 00:00:00' ) AND ( dt.booking_date <= '2016-12-31 23:59:59' ) ) AND bk.trash = 0 AND ( ( bk.booking_type IN ( 14,15,16,17,18,20,21,22,23,1,2,3,4,5,26,6,7,8,9,10,11,12,24,25 ) ) ) ORDER BY booking_type DESC LIMIT 0, 100000
815 - [TIME] => 18.3653769493
816 - [2] => do_action('toplevel_page_wpbc'), call_user_func_array, WPBC_Admin_Menus->content, do_action('wpbc_page_structure_show'), call_user_func_array, WPBC_Page_Structure->content_structure, WPBC_Page_CalendarOverview->content, WPBC_Timeline->admin_init, wpbc_get_bookings_objects
817 - )
818 - (
819 - [0] => SELECT COUNT(*) as count FROM wp_booking as bk WHERE EXISTS (
820 - SELECT *
821 - FROM wp_bookingdates as dt
822 - WHERE bk.booking_id = dt.booking_id AND ( dt.booking_date >= '2016-11-01 00:00:00' ) AND ( dt.booking_date <= '2016-12-31 23:59:59' ) ) AND bk.trash = 0 AND ( ( bk.booking_type IN ( 14,15,16,17,18,20,21,22,23,1,2,3,4,5,26,6,7,8,9,10,11,12,24,25 ) ) )
823 - [TIME] => 18.0764019489
824 - [2] => do_action('toplevel_page_wpbc'), call_user_func_array, WPBC_Admin_Menus->content, do_action('wpbc_page_structure_show'), call_user_func_array, WPBC_Page_Structure->content_structure, WPBC_Page_CalendarOverview->content, WPBC_Timeline->admin_init, wpbc_get_bookings_objects
825 - )
826 - */
827 -
828 - // Index for SPEED opening Booking Listing and Timeline with thousands of Bookings, otherwise, without this index, speed will be TOO SLOW...
829 - if (wpbc_is_index_in_table_exists('bookingdates','booking_id_dates') == 0) {
830 - $simple_sql = "CREATE UNIQUE INDEX booking_id_dates ON {$wpdb->prefix}bookingdates ( booking_id, booking_date);";
831 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
435 + if ( 0 === wpbc_is_index_in_table_exists( 'bookingdates', 'booking_id_dates' ) ) {
436 + // If we remove this index, so then its can significant impact to the speed of page loading at the Booking Listing and Timelines.
437 + // Index for SPEED opening Booking Listing and Timeline with thousands of Bookings, otherwise, without this index, speed will be TOO SLOW...
438 + $simple_sql = "CREATE UNIQUE INDEX booking_id_dates ON {$wpdb->prefix}bookingdates ( booking_id, booking_date);";
439 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
832 440 $wpdb->query( $simple_sql );
833 - }
834 -
835 -
836 - if (count($wp_queries)>0) {
837 - foreach ( $wp_queries as $wp_q ) {
838 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
839 - $wpdb->query( $wp_q );
840 - }
441 + }
841 442
842 - if( ! class_exists( 'wpdev_bk_personal' ) ) {
843 - $temp_id = $wpdb->insert_id;
844 - $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates (
845 - booking_id,
846 - booking_date
847 - ) VALUES
848 - ( ". $temp_id .", CURDATE()+ INTERVAL 2 day ),
849 - ( ". $temp_id .", CURDATE()+ INTERVAL 3 day ),
850 - ( ". $temp_id .", CURDATE()+ INTERVAL 4 day );";
851 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
852 - $wpdb->query( $wp_queries_sub );
853 - }
854 - }
443 + // ----------------------------------------------------------------------------
444 + // 3. Insert test bookings.
445 + // ----------------------------------------------------------------------------
855 446
856 - // FixIn: 9.2.3.3.
857 - if ( wpbc_is_field_in_table_exists( 'booking', 'hash' ) == 0 ) { //HASH_EDIT
447 + if ( $is_insert_test_bookings ) {
448 + // -- Test Booking #1 --
449 + $is_appr = 1;
450 + $wp_queries_sub = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date ) VALUES (
451 + 'text^firstname1^John~text^secondname1^Smith~text^email1^[email protected]~text^phone1^458-77-77~textarea^details1^This is a test booking showing booking for several days.', " . wpbc_sql_date_math_expr_explicit('', 'now') . " );";
452 + $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
858 453
859 - $simple_sql = "ALTER TABLE {$wpdb->prefix}booking ADD hash TEXT AFTER form";
860 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
861 - $wpdb->query( $simple_sql );
454 + $temp_id = $wpdb->insert_id;
455 + $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates ( booking_id, booking_date, approved ) VALUES
456 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 2 DAY", 'curdate' ) . " ," . $is_appr . " ),
457 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 3 DAY", 'curdate' ) . " ," . $is_appr . " ),
458 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 4 DAY", 'curdate' ) . " ," . $is_appr . " );";
459 + $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
862 460
863 - // Update hash value only in last 100 bookings
864 - $sql_check_table = "SELECT booking_id as id FROM {$wpdb->prefix}booking ORDER BY booking_id DESC LIMIT 0, 100";
461 + // -- Test Booking #2 --
462 + $is_appr = 0;
463 + $wp_queries_sub = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date ) VALUES (
464 + 'text^firstname1^Emma~text^secondname1^Robinson~text^email1^[email protected]~text^phone1^999-77-77~textarea^details1^This is a test booking showing booking for several days.', " . wpbc_sql_date_math_expr_explicit('', 'now') . " );";
465 + $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
865 466
866 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
867 - $res = $wpdb->get_results( $sql_check_table );
467 + $temp_id = $wpdb->insert_id;
468 + $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates ( booking_id, booking_date, approved ) VALUES
469 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 28 DAY", 'curdate' ) . " ," . $is_appr . " ),
470 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 29 DAY", 'curdate' ) . " ," . $is_appr . " ),
471 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 30 DAY", 'curdate' ) . " ," . $is_appr . " );";
472 + $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
868 473
869 - foreach ( $res as $l ) {
870 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
871 - $wpdb->query( "UPDATE {$wpdb->prefix}booking SET hash = MD5('" . time() . '_' . wp_rand( 1000, 1000000 ) . "') WHERE booking_id = " . $l->id );
872 - }
474 +
475 + // -- Test Booking #3 --
476 + $is_appr = 1;
477 + $start_time = '10:00';
478 + $end_time = '10:30';
479 + $wp_queries_sub = "INSERT INTO {$wpdb->prefix}booking ( form, modification_date, is_new ) VALUES (
480 + 'selectbox^rangetime1^".$start_time." - ".$end_time."~text^firstname1^Sophia~text^secondname1^Robinson~text^email1^[email protected]~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 );";
481 + $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
482 +
483 + $temp_id = $wpdb->insert_id;
484 +
485 + $start_time_arr = explode( ':', $start_time );
486 + $end_time_arr = explode( ':', $end_time );
487 + $wp_queries_sub = "INSERT INTO {$wpdb->prefix}bookingdates ( booking_id, booking_date, approved ) VALUES
488 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '" . ( ( 8 * 24 ) + intval( $start_time_arr[0] ) ) . ':' . $start_time_arr[1] . ":01' HOUR_SECOND", 'curdate' ) . " ," . $is_appr . " ),
489 + ( " . $temp_id . ", " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '" . ( ( 8 * 24 ) + intval( $end_time_arr[0] ) ) . ':' . $end_time_arr[1] . ":02' HOUR_SECOND", 'curdate' ) . " ," . $is_appr . " );";
490 + $wpdb->query( $wp_queries_sub ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
873 491 }
874 492 }
875 - make_bk_action( 'wpbc_activation_after_db_actions' ); // FixIn: 9.3.1.2.
876 493
494 + make_bk_action( 'wpbc_free_version_activation' );
495 +
496 + do_action( 'wpbc_free_version_activation' );
497 +
877 498 // -----------------------------------------------------------------------------------------------------------------
878 - // Other versions Activation
499 + // Other versions Activation
879 500 // -----------------------------------------------------------------------------------------------------------------
880 - make_bk_action( 'wpbc_other_versions_activation' );
501 + make_bk_action( 'wpbc_other_versions_activation' );
881 502
882 -
883 - // -----------------------------------------------------------------------------------------------------------------
884 - // Examples in demos
885 - // -----------------------------------------------------------------------------------------------------------------
886 - if ( $is_demo ) { wpbc_create_examples_4_demo(); }
503 + do_action( 'wpbc_pro_versions_activation' );
887 504
888 -
889 - // Fill Development server by initial bookings
890 - if ( ( defined( 'WP_BK_BETA_DATA_FILL' ) )
891 - && ( WP_BK_BETA_DATA_FILL > 0 )
892 - ) {
893 - if ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( ( 'beta' === $_SERVER['HTTP_HOST'] ) || ( 'freetest.wpbookingcalendar.com' === $_SERVER['HTTP_HOST'] ) ) ) {
894 - $types_array = array();
895 - for ( $i = 0; $i < WP_BK_BETA_DATA_FILL; $i++) {
896 - foreach ( range(1, 12) as $types_el) {
897 - $types_array[] = $types_el;
898 - }
899 - }
900 - wpbc_create_examples_4_demo( $types_array );
901 - }
902 - }
903 - //wpbc_set_default_initial_values();
505 + wpbc_reindex_booking_db();
904 506
905 - // -----------------------------------------------------------------------------------------------------------------
906 - wpbc_reindex_booking_db();
507 + make_bk_action( 'wpbc_after_activation' );
907 508
908 - make_bk_action( 'wpbc_after_activation' );
509 + do_action( 'wpbc_after_activation' );
909 510 }
910 511 add_bk_action( 'wpbc_activation', 'wpbc_booking_activate' );
911 512
912 513
514 +/**
515 + * Determine whether the commercial registration data must survive full data removal.
516 + *
517 + * Demo sites need to retain the validated commercial registration payload so that
518 + * resetting demo booking data does not expose the order-number registration form.
519 + * Requiring both the established demo check and the official domain prevents this
520 + * exception from changing cleanup behavior on customer, local, or beta websites.
521 + *
522 + * @return bool True when registration data must be preserved; otherwise false.
523 + */
524 +function wpbc_deactivation__should_preserve_registration_data() {
913 525
914 -// Deactivate
526 + if ( ! function_exists( 'wpbc_is_this_demo' ) || ! wpbc_is_this_demo() ) {
527 + return false;
528 + }
529 +
530 + $site_host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
531 +
532 + if ( ! is_string( $site_host ) || '' === $site_host ) {
533 + return false;
534 + }
535 +
536 + $site_host = strtolower( rtrim( $site_host, '.' ) );
537 + $official_demo_host = 'wpbookingcalendar.com';
538 + $official_demo_suffix = '.' . $official_demo_host;
539 +
540 + if ( $official_demo_host === $site_host ) {
541 + return true;
542 + }
543 +
544 + return strlen( $site_host ) > strlen( $official_demo_suffix )
545 + && $official_demo_suffix === substr( $site_host, -strlen( $official_demo_suffix ) );
546 +}
547 +
548 +
549 +/**
550 + * Delete every site option and transient owned by Booking Calendar.
551 + *
552 + * The historical deactivation path deletes options returned by
553 + * wpbc_get_default_options(). Runtime modules also create version markers,
554 + * setup state, caches, and transients outside that registry. This final pass
555 + * runs after all module callbacks so those callbacks can still read their
556 + * settings while removing tables and other data.
557 + *
558 + * @return void
559 + */
560 +function wpbc_deactivation__delete_all_plugin_options() {
561 +
562 + global $wpdb;
563 +
564 + $option_name_patterns = array(
565 + $wpdb->esc_like( 'booking_' ) . '%',
566 + $wpdb->esc_like( 'wpbc_' ) . '%',
567 + $wpdb->esc_like( '_transient_' ) . '%' . $wpdb->esc_like( 'booking_' ) . '%',
568 + $wpdb->esc_like( '_transient_' ) . '%' . $wpdb->esc_like( 'wpbc_' ) . '%',
569 + $wpdb->esc_like( '_site_transient_' ) . '%' . $wpdb->esc_like( 'booking_' ) . '%',
570 + $wpdb->esc_like( '_site_transient_' ) . '%' . $wpdb->esc_like( 'wpbc_' ) . '%',
571 + );
572 +
573 + $sql = $wpdb->prepare(
574 + "SELECT option_name
575 + FROM {$wpdb->options}
576 + WHERE option_name LIKE %s
577 + OR option_name LIKE %s
578 + OR option_name LIKE %s
579 + OR option_name LIKE %s
580 + OR option_name LIKE %s
581 + OR option_name LIKE %s",
582 + $option_name_patterns
583 + );
584 +
585 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
586 + $option_names = $wpdb->get_col( $sql );
587 + $option_names = is_array( $option_names ) ? array_unique( $option_names ) : array();
588 +
589 + if ( ! wpbc_deactivation__should_preserve_registration_data() ) {
590 + $option_names[] = 'bk_version_data';
591 + }
592 +
593 + foreach ( $option_names as $option_name ) {
594 + delete_option( $option_name );
595 + }
596 +}
597 +
598 +
599 +
600 +// Deactivate.
915 601 function wpbc_booking_deactivate() {
916 602
917 603 // -----------------------------------------------------------------------------------------------------------------
918 604 // Options
@@ -931,21 +617,27 @@
931 617 delete_bk_option( 'widget_bookingsearchwidget' );
932 618 delete_bk_option( 'widget_bookingselectwidget' );
933 619 delete_bk_option( 'booking_activation_redirect_for_version' );
934 620
935 -
936 621 // -----------------------------------------------------------------------------------------------------------------
937 622 // DB Tables
938 623 // -----------------------------------------------------------------------------------------------------------------
939 624 global $wpdb;
940 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange
625 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.SchemaChange
941 626 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}booking" );
942 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange
627 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.SchemaChange
943 628 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}bookingdates" );
944 629
945 - // Delete all users booking windows states.
946 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared,
947 - if ( false === $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%booking_%'" ) ) {
630 + // Delete all Booking Calendar user options, listing state, and dismissed notices.
631 + $booking_meta_pattern = '%' . $wpdb->esc_like( 'booking_' ) . '%';
632 + $wpbc_meta_pattern = '%' . $wpdb->esc_like( 'wpbc_' ) . '%';
633 + $user_meta_delete_sql = $wpdb->prepare(
634 + "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s OR meta_key LIKE %s",
635 + $booking_meta_pattern,
636 + $wpbc_meta_pattern
637 + );
638 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
639 + if ( false === $wpdb->query( $user_meta_delete_sql ) ) {
948 640 debuge_error('Error during deleting user meta at DB',__FILE__,__LINE__);
949 641 die();
950 642 }
951 643
@@ -950,19 +642,21 @@
950 642 }
951 643
952 644 // Delete or Drafts and Pending from demo sites
953 645 if ( wpbc_is_this_demo() ) { // Delete all temp posts at the demo sites: (post_status = pending || draft) && ( post_type = post ) && (post_author != 1)
954 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared,
646 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter,
955 647 $postss = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE ( post_status = 'pending' OR post_status = 'draft' OR post_status = 'auto-draft' OR post_status = 'trash' OR post_status = 'inherit' ) AND ( post_type='post' OR post_type='revision') AND post_author != 1" );
956 648 foreach ( $postss as $pp ) {
957 649 wp_delete_post( $pp->ID, true );
958 650 }
959 651 }
960 -
652 + make_bk_action( 'wpbc_free_version_deactivation' );
961 653 ////////////////////////////////////////////////////////////////////////////
962 654 // Other versions Deactivation
963 655 ////////////////////////////////////////////////////////////////////////////
964 656 make_bk_action( 'wpbc_other_versions_deactivation' );
657 +
658 + wpbc_deactivation__delete_all_plugin_options();
965 659 }
966 660 add_bk_action( 'wpbc_deactivation', 'wpbc_booking_deactivate' );
967 661
968 662
@@ -976,10 +670,11 @@
976 670 * $options_for_delete = wpbc_get_default_options( $option_name, $is_get_multiuser_general_options );
977 671 */
978 672 function wpbc_get_default_options( $option_name = '', $is_get_multiuser_general_options = false ) {
979 673
980 - $is_demo = wpbc_is_this_demo();
981 - $blg_title = str_replace( array( '"', "'" ), '', get_option( 'blogname' ) );
674 + $is_demo = wpbc_is_this_demo();
675 + $is_free_version = ! class_exists( 'wpdev_bk_personal' );
676 + $blg_title = str_replace( array( '"', "'" ), '', get_option( 'blogname' ) );
982 677
983 678 $default_options = array();
984 679
985 680 // If this option here, then system get this option from "Super Admin" options configuration for "Regular" users.
@@ -984,23 +679,29 @@
984 679
985 680 // If this option here, then system get this option from "Super Admin" options configuration for "Regular" users.
986 681 $mu_option4delete = array();
987 682
988 - // FixIn: 9.6.3.5.
989 - $default_options['booking_setup_wizard_page_steps_is_done'] = '';
990 - $mu_option4delete[]='booking_setup_wizard_page_steps_is_done';
683 + $default_options['booking_setup_wizard_initial_install'] = 'Off';
684 + $mu_option4delete[] = 'booking_setup_wizard_initial_install';
685 + $default_options['booking_setup_wizard_first_run_prompt'] = 'Off';
686 + $mu_option4delete[] = 'booking_setup_wizard_first_run_prompt';
687 + $default_options['booking_setup_wizard_booking_pages_prompt'] = 'Off';
688 + $mu_option4delete[] = 'booking_setup_wizard_booking_pages_prompt';
689 + $default_options['booking_update_navigation_context'] = array();
690 + $mu_option4delete[] = 'booking_update_navigation_context';
991 691
992 692 $default_options['booking_admin_cal_count'] = ($is_demo) ? '3' : '2';
993 693 $mu_option4delete[]='booking_admin_cal_count'; // $multiuser_general_option[] = implode( '', array_keys( array_slice( $default_options, -1 ) ) );
994 - $default_options['booking_skin'] = '/css/skins/24_9__light_square_1.css';
694 + $default_options['booking_skin'] = '/css/skins/25_5__square_1.css'; // FixIn: 10.11.4.2.
995 695 $mu_option4delete[]='booking_skin';
996 696 // FixIn: 9.6.3.5.
997 697 $default_options['booking_listing_default_view_mode'] = 'vm_booking_listing'; // 'vm_calendar'; // FixIn: 9.6.3.5.
998 698 $mu_option4delete[]='booking_listing_default_view_mode';
699 + $default_options['booking_admin_edit_booking_mode'] = 'popup';
700 + $mu_option4delete[]='booking_admin_edit_booking_mode';
701 + $default_options['booking_resources_catalog_default_view'] = '';
702 + $mu_option4delete[] = 'booking_resources_catalog_default_view';
999 703
1000 -// $default_options['booking_admin_panel_skin'] = 'modern_1'; // 'modern_1' //FixIn: 9.5.5.7 // FixIn: 10.1.1.3.
1001 -// $mu_option4delete[]='booking_admin_panel_skin';
1002 -
1003 704 $default_options['booking_view_days_num'] = ( ( ! class_exists( 'wpdev_bk_personal' ) ) ? '90' : '30' );
1004 705 $mu_option4delete[]='booking_view_days_num';
1005 706 // FixIn: 8.9.4.3.
1006 707 $default_options['booking_calendar_overview__day_mode__days_number_show'] = ( ( ! class_exists( 'wpdev_bk_personal' ) ) ? '7' : '7' );
@@ -1022,12 +723,17 @@
1022 723 //$mu_option4delete[]='booking_title_after_reservation_time';
1023 724 $default_options['booking_type_of_thank_you_message'] = 'message';
1024 725 $mu_option4delete[]='booking_type_of_thank_you_message';
1025 726 $default_options['booking_thank_you_page_URL'] = '/thank-you';
1026 - $mu_option4delete[]='booking_thank_you_page_URL';
727 + $mu_option4delete[]='booking_thank_you_page_URL';
1027 728 $default_options['booking_is_use_autofill_4_logged_user'] = ($is_demo) ? 'On' : 'Off';
1028 - $mu_option4delete[]='booking_is_use_autofill_4_logged_user';
1029 - $default_options['booking_date_format'] = get_option( 'date_format' );
729 + $mu_option4delete[]='booking_is_use_autofill_4_logged_user';
730 +
731 + // FixIn: 10.13.1.5.
732 + $default_options['booking_is_use_phone_validation'] = 'Off';
733 + $mu_option4delete[]='booking_is_use_phone_validation';
734 + $wordpress_date_format = get_option( 'date_format' );
735 + $default_options['booking_date_format'] = ( 'F j, Y' === $wordpress_date_format ) ? 'j M Y' : $wordpress_date_format;
1030 736 $mu_option4delete[]='booking_date_format';
1031 737 $default_options['booking_time_format'] = get_option( 'time_format' ); //'H:i';
1032 738 $mu_option4delete[]='booking_time_format';
1033 739
@@ -1048,9 +754,9 @@
1048 754
1049 755 $default_options['booking_confirmation__booking_details__header_enabled'] = 'On';
1050 756 $default_options['booking_confirmation__booking_details__title'] = __( 'Booking details', 'booking' );
1051 757 $default_options['booking_confirmation__booking_details__content'] = ( class_exists( 'wpdev_bk_personal' ) )
1052 - ? "<h4>[resource_title]</h4>[readable_dates][readable_times]\n[add_to_google_cal_button]"
758 + ? "<h4>[resource_title]</h4>[readable_dates][readable_times]\n[add_to_google_cal_button]\n" . '<a href="[visitorbookingediturl]">Edit Booking</a> | <a href="[visitorbookingcancelurl]">Cancel Booking</a>'
1053 759 : "[readable_dates][readable_times]\n[add_to_google_cal_button]";
1054 760
1055 761 $mu_option4delete[] = 'booking_confirmation__booking_details__header_enabled';
1056 762 $mu_option4delete[] = 'booking_confirmation__booking_details__title';
@@ -1079,21 +785,19 @@
1079 785
1080 786 $mu_option4delete[]='booking_is_load_js_css_on_specific_pages';
1081 787 $default_options['booking_pages_for_load_js_css'] = '';
1082 788 $mu_option4delete[]='booking_pages_for_load_js_css';
1083 - $default_options['booking_type_of_day_selections'] = ( ( get_bk_option( 'booking_range_selection_is_active' ) == 'On' ) && ( ! $is_demo ) ) ? 'range' : 'multiple';
789 + $default_options['booking_type_of_day_selections'] = $is_free_version
790 + ? 'range'
791 + : ( ( get_bk_option( 'booking_range_selection_is_active' ) == 'On' ) && ( ! $is_demo ) ? 'range' : 'multiple' );
1084 792 $mu_option4delete[]='booking_type_of_day_selections';
1085 793
1086 794 // FixIn: 8.7.11.10.
1087 795 $default_options['booking_timeslot_picker'] = 'On';
1088 796 $mu_option4delete[]= 'booking_timeslot_picker';
1089 - $default_options['booking_timeslot_picker_skin'] = '/css/time_picker_skins/light__24_8.css';
797 + $default_options['booking_timeslot_picker_skin'] = '/css/time_picker_skins/form_style.css';
1090 798 $mu_option4delete[]= 'booking_timeslot_picker_skin';
1091 799
1092 - $default_options['booking_timeslot_day_bg_as_available'] = 'Off'; //( ( class_exists( 'wpdev_bk_personal' ) ) ? 'Off' : 'On' ); // FixIn: 8.2.1.27.
1093 - $mu_option4delete[]='booking_timeslot_day_bg_as_available';
1094 -
1095 -
1096 800 $default_options['booking_disable_timeslots_in_tooltip'] = 'Off'; //FixIn: 9.5.0.2.2
1097 801 $mu_option4delete[]='booking_disable_timeslots_in_tooltip';
1098 802
1099 803 $default_options['booking_highlight_timeslot_word'] = __( 'Booked Times:', 'booking' ); // FixIn: 9.4.3.1.
@@ -1148,25 +852,40 @@
1148 852 $default_options['booking_unavailable_day5'] = 'Off';
1149 853 $mu_option4delete[]='booking_unavailable_day5';
1150 854 $default_options['booking_unavailable_day6'] = 'Off';
1151 855 $mu_option4delete[]='booking_unavailable_day6';
856 +
857 + // Working Time defaults. Keep disabled by default on fresh activation/reinstall.
858 + $default_options['booking_working_time_enabled'] = 'Off';
859 + $mu_option4delete[]='booking_working_time_enabled';
860 + $default_options['booking_working_time_rules'] = function_exists( 'wpbc_working_time__get_default_settings' ) ? wpbc_working_time__get_default_settings() : array(
861 + 'enabled' => 'Off',
862 + 'default' => array(
863 + 'weekdays' => array(),
864 + ),
865 + 'resources' => array(),
866 + );
867 + $mu_option4delete[]='booking_working_time_rules';
868 +
1152 869 $default_options['booking_menu_position'] = ( $is_demo ) ? 'top' : 'top';
1153 870 $mu_option4delete[]='booking_menu_position';
1154 871 $default_options['booking_translation_load_from'] = 'wp.org';
1155 872 $mu_option4delete[]='booking_translation_load_from';
1156 - $default_options['booking_user_role_booking'] = ( $is_demo ) ? 'subscriber' : 'editor';
873 +
874 + // FixIn: 10.14.12.1.
875 + $default_options['booking_user_role_booking'] = 'editor';
1157 876 $mu_option4delete[]='booking_user_role_booking';
1158 - $default_options['booking_user_role_availability'] = ( $is_demo ) ? 'subscriber' : 'editor'; // FixIn: 9.5.2.2.
877 + $default_options['booking_user_role_availability'] = 'editor';
1159 878 $mu_option4delete[]='booking_user_role_availability';
1160 - $default_options['booking_user_role_addbooking'] = ( $is_demo ) ? 'subscriber' : 'editor';
879 + $default_options['booking_user_role_addbooking'] = 'editor';
1161 880 $mu_option4delete[]='booking_user_role_addbooking';
1162 - $default_options['booking_user_role_resources'] = ( $is_demo ) ? 'subscriber' : 'editor';
881 + $default_options['booking_user_role_resources'] = 'editor';
1163 882 $mu_option4delete[]='booking_user_role_resources';
1164 - $default_options['booking_user_role_settings'] = ( $is_demo ) ? 'subscriber' : 'administrator';
883 + $default_options['booking_user_role_settings'] = 'editor';
1165 884 $mu_option4delete[]='booking_user_role_settings';
1166 885 //FixIn: 9.8.15.2.6
1167 886 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
1168 - $default_options['booking_user_role_prices'] = ( $is_demo ) ? 'subscriber' : 'editor';
887 + $default_options['booking_user_role_prices'] = 'editor';
1169 888 $mu_option4delete[]='booking_user_role_prices';
1170 889 }
1171 890
1172 891 // New admin ///////////////////////////////////////////////////////////////
@@ -1221,15 +940,83 @@
1221 940 $default_options['booking_widget_last_field'] = '';
1222 941
1223 942 $default_options['booking_wpdev_copyright_adminpanel'] = 'On';
1224 943 $mu_option4delete[]='booking_wpdev_copyright_adminpanel';
1225 - $default_options['booking_is_show_powered_by_notice'] = 'On';
944 + $default_options['booking_is_show_powered_by_notice'] = ( WPBC_IS_PLAYGROUND ) ? 'Off' : 'On';
1226 945 $mu_option4delete[]='booking_is_show_powered_by_notice';
1227 946 $default_options['booking_form_theme'] = '';
1228 947 $mu_option4delete[]='booking_form_theme';
1229 - $default_options['booking_is_use_captcha'] = 'Off';
948 + $default_options['booking_form_style'] = 'light_bordered';
949 + $mu_option4delete[]='booking_form_style';
950 + $default_options['booking_form_accent_enabled'] = 'Off';
951 + $mu_option4delete[]='booking_form_accent_enabled';
952 + $default_options['booking_form_accent_color'] = WPBC_DEFAULT_FORM_ACCENT_COLOR;
953 + $mu_option4delete[]='booking_form_accent_color';
954 + $default_options['booking_form_appearance_preset'] = 'bordered';
955 + $mu_option4delete[]='booking_form_appearance_preset';
956 + $default_options['booking_form_appearance_background_color'] = '#ffffff';
957 + $mu_option4delete[]='booking_form_appearance_background_color';
958 + $default_options['booking_form_appearance_border_color'] = '#cccccc';
959 + $mu_option4delete[]='booking_form_appearance_border_color';
960 + $default_options['booking_form_appearance_border_width'] = '1px';
961 + $mu_option4delete[]='booking_form_appearance_border_width';
962 + $default_options['booking_form_appearance_border_radius'] = '2px';
963 + $mu_option4delete[]='booking_form_appearance_border_radius';
964 + $default_options['booking_form_appearance_padding'] = '10px 30px';
965 + $mu_option4delete[]='booking_form_appearance_padding';
966 + $default_options['booking_form_custom_background_color'] = '#ffffff';
967 + $mu_option4delete[]='booking_form_custom_background_color';
968 + $default_options['booking_form_custom_border_color'] = '#cccccc';
969 + $mu_option4delete[]='booking_form_custom_border_color';
970 + $default_options['booking_form_custom_border_width'] = '1px';
971 + $mu_option4delete[]='booking_form_custom_border_width';
972 + $default_options['booking_form_custom_border_radius'] = '2px';
973 + $mu_option4delete[]='booking_form_custom_border_radius';
974 + $default_options['booking_form_custom_padding_vertical'] = '10px';
975 + $mu_option4delete[]='booking_form_custom_padding_vertical';
976 + $default_options['booking_form_custom_padding_horizontal'] = '30px';
977 + $mu_option4delete[]='booking_form_custom_padding_horizontal';
978 + $default_options['booking_form_custom_text_color'] = '#1d2327';
979 + $mu_option4delete[]='booking_form_custom_text_color';
980 + $default_options['booking_form_custom_field_background_color'] = '#ffffff';
981 + $mu_option4delete[]='booking_form_custom_field_background_color';
982 + $default_options['booking_form_custom_field_text_color'] = '#3c434a';
983 + $mu_option4delete[]='booking_form_custom_field_text_color';
984 + $default_options['booking_form_custom_field_border_color'] = '#cccccc';
985 + $mu_option4delete[]='booking_form_custom_field_border_color';
986 + $default_options['booking_form_custom_button_background_color'] = '#066aab';
987 + $mu_option4delete[]='booking_form_custom_button_background_color';
988 + $default_options['booking_form_custom_button_text_color'] = '#ffffff';
989 + $mu_option4delete[]='booking_form_custom_button_text_color';
990 + $default_options['booking_form_custom_button_border_color'] = '#066aab';
991 + $mu_option4delete[]='booking_form_custom_button_border_color';
992 + $default_options['booking_form_custom_button_hover_background_color'] = '#055589';
993 + $mu_option4delete[]='booking_form_custom_button_hover_background_color';
994 + $default_options['booking_form_custom_button_hover_text_color'] = '#ffffff';
995 + $mu_option4delete[]='booking_form_custom_button_hover_text_color';
996 + $default_options['booking_form_custom_button_hover_border_color'] = '#055589';
997 + $mu_option4delete[]='booking_form_custom_button_hover_border_color';
998 + $default_options['booking_form_custom_secondary_button_background_color'] = '#fdfdfd';
999 + $mu_option4delete[]='booking_form_custom_secondary_button_background_color';
1000 + $default_options['booking_form_custom_secondary_button_text_color'] = '#444444';
1001 + $mu_option4delete[]='booking_form_custom_secondary_button_text_color';
1002 + $default_options['booking_form_custom_secondary_button_border_color'] = '#eeeeee';
1003 + $mu_option4delete[]='booking_form_custom_secondary_button_border_color';
1004 + $default_options['booking_form_custom_secondary_button_hover_background_color'] = '#fdfdfd';
1005 + $mu_option4delete[]='booking_form_custom_secondary_button_hover_background_color';
1006 + $default_options['booking_form_custom_secondary_button_hover_text_color'] = '#444444';
1007 + $mu_option4delete[]='booking_form_custom_secondary_button_hover_text_color';
1008 + $default_options['booking_form_custom_secondary_button_hover_border_color'] = '#4d91cd';
1009 + $mu_option4delete[]='booking_form_custom_secondary_button_hover_border_color';
1010 + $default_options['booking_form_custom_button_border_width'] = '1px';
1011 + $mu_option4delete[]='booking_form_custom_button_border_width';
1012 + $default_options['booking_form_custom_button_border_radius'] = '3px';
1013 + $mu_option4delete[]='booking_form_custom_button_border_radius';
1014 + $default_options['booking_is_use_captcha'] = 'Off';
1230 1015 $mu_option4delete[]='booking_is_use_captcha';
1231 - $default_options['booking_is_show_legend'] = 'On';
1016 + $default_options['booking_frontend_messages'] = array( 'version' => 1, 'messages' => array(), 'enabled' => array() );
1017 + $mu_option4delete[]='booking_frontend_messages';
1018 + $default_options['booking_is_show_legend'] = 'On';
1232 1019 $mu_option4delete[]='booking_is_show_legend';
1233 1020 $default_options['booking_send_button_title'] = __( 'Send', 'booking' ); // FixIn: 8.8.1.14.
1234 1021 $mu_option4delete[]='booking_send_button_title';
1235 1022 $default_options['booking_legend_is_show_item_available'] = 'On';
@@ -1275,8 +1062,10 @@
1275 1062 $emails_init = array_merge( $emails_init, wpbc_import6_email__deny__get_fields_array_for_activation() );
1276 1063 $emails_init = array_merge( $emails_init, wpbc_import6_email__trash__get_fields_array_for_activation() );
1277 1064 if ( class_exists( 'wpdev_bk_personal' ) )
1278 1065 $emails_init = array_merge( $emails_init, wpbc_import6_email__modification__get_fields_array_for_activation() );
1066 + if ( class_exists( 'wpdev_bk_personal' ) && function_exists( 'wpbc_customer_verification_email_get_initial_values' ) )
1067 + $emails_init = array_merge( $emails_init, wpbc_customer_verification_email_get_initial_values() );
1279 1068 if ( class_exists( 'wpdev_bk_biz_s' ) )
1280 1069 $emails_init = array_merge( $emails_init, wpbc_import6_email__payment_request__get_fields_array_for_activation() );
1281 1070 foreach ( $emails_init as $email_key_name => $email_values ) {
1282 1071
@@ -1290,29 +1079,31 @@
1290 1079 $mu_option4delete[]='booking_cron'; // Creation in wpbc-cron.php
1291 1080
1292 1081 // FixIn: 8.0.1.6.
1293 1082 //$default_options['booking_form_structure_type'] = 'vertical';
1294 - $default_options['booking_form_structure_type'] = 'form_right'; // FixIn: 10.3.0.6.
1295 - $default_options['booking_menu_go_pro'] = 'show'; // show | hide
1083 + // $default_options['booking_form_structure_type'] = 'form_right'; // FixIn: 10.3.0.6.
1084 + $default_options['booking_form_structure_type'] = 'wizard_services_a'; // FixIn: 10.11.4.3.
1085 + $default_options['booking_menu_go_pro'] = ( WPBC_IS_PLAYGROUND ) ? 'hide' : 'show'; // show | hide
1296 1086
1297 - $default_options['booking_form_layout_width'] = '440';
1298 - $default_options['booking_form_layout_width_px_pr'] = 'px';
1299 - $default_options['booking_form_layout_max_cols'] = 1;
1087 +// $default_options['booking_form_layout_width'] = '440';
1088 +// $default_options['booking_form_layout_width_px_pr'] = 'px';
1089 +// $default_options['booking_form_layout_max_cols'] = 1;
1300 1090
1091 + // FixIn: 10.11.4.3.
1092 + $default_options['booking_form_layout_width'] = '100';
1093 + $default_options['booking_form_layout_width_px_pr'] = '%';
1094 + $default_options['booking_form_layout_max_cols'] = 2;
1095 +
1096 +
1301 1097 // -----------------------------------------------------------------------------------------------------------------
1302 1098 // PS
1303 1099 // -----------------------------------------------------------------------------------------------------------------
1304 1100 if ( class_exists( 'wpdev_bk_personal' ) ) {
1305 1101
1306 - $default_options['booking_is_use_simple_booking_form'] = 'Off'; // FixIn: 8.1.1.12.
1307 - $mu_option4delete[]='booking_is_use_simple_booking_form';
1308 1102
1309 1103 $default_options['booking_is_use_codehighlighter_booking_form'] = 'On'; // FixIn: 8.4.7.18.
1310 1104 $mu_option4delete[]='booking_is_use_codehighlighter_booking_form';
1311 1105
1312 - $default_options['booking_form'] = str_replace( '\\n\\', '', wpbc_get_default_booking_form() );
1313 - $default_options['booking_form_show'] = str_replace( '\\n\\', '', wpbc_get_default_booking_form_show() );
1314 -
1315 1106 $default_options['booking_url_bookings_edit_by_visitors'] = site_url();
1316 1107 $mu_option4delete[]='booking_url_bookings_edit_by_visitors';
1317 1108
1318 1109 $default_options['booking_url_bookings_listing_by_customer'] = site_url(); //FixIn: 8.1.3.5.1
@@ -1340,9 +1131,10 @@
1340 1131 $mu_option4delete[]='booking_calendar_overview_end_time';
1341 1132
1342 1133 $default_options['booking_default_title_in_day_for_timeline_front_end'] = '[name] [secondname]';
1343 1134 $mu_option4delete[]='booking_default_title_in_day_for_timeline_front_end';
1344 - $default_options['booking_is_show_popover_in_timeline_front_end'] = ($is_demo) ? 'On' : 'Off';
1135 + // FixIn: 10.14.10.1.
1136 + $default_options['booking_is_show_popover_in_timeline_front_end'] = 'Off';
1345 1137 $mu_option4delete[]='booking_is_show_popover_in_timeline_front_end';
1346 1138 // FixIn: 9.6.3.5.
1347 1139
1348 1140 $default_options['booking_send_emails_off_addbooking'] = 'Off'; // FixIn: 8.4.5.4.
@@ -1365,8 +1157,11 @@
1365 1157 //$mu_option4delete[]='booking_ics_force_trash_before_import'; // No need to delete ^
1366 1158 $default_options['booking_ics_import_append_checkout_day'] = 'Off'; //FixIn: 9.6.2.7 // FixIn: 9.5.4.1.
1367 1159 //$mu_option4delete[]='booking_ics_import_append_checkout_day'; // No need to delete ^
1368 1160
1161 + $default_options['booking_ics_import_append_extra_checkout_day'] = 'Off';
1162 + //$mu_option4delete[]='booking_ics_import_append_extra_checkout_day'; // No need to delete ^
1163 +
1369 1164 // FixIn: 9.8.15.8.
1370 1165 $default_options['booking_condition_import_only_new'] = ( get_bk_option( 'booking_ics_force_import' ) === 'On' ) ? 'Off' : 'On';
1371 1166 $default_options['booking_condition_import_if_available'] = 'Off';
1372 1167
@@ -1415,9 +1210,11 @@
1415 1210 $default_options['booking_auto_cancel_pending_unpaid_bk_is_send_email'] = 'On';
1416 1211 $mu_option4delete[]='booking_auto_cancel_pending_unpaid_bk_is_send_email';
1417 1212 $default_options['booking_auto_cancel_pending_unpaid_bk_email_reason'] = __( 'This booking canceled because we did not receive payment and the administrator did not approve it.', 'booking' );
1418 1213 $mu_option4delete[]='booking_auto_cancel_pending_unpaid_bk_email_reason';
1419 - $default_options['booking_range_selection_type'] = 'fixed';
1214 + // Start every edition with the unrestricted two-click range.
1215 + // Business Small+ users can opt into a fixed one-click range later.
1216 + $default_options['booking_range_selection_type'] = 'dynamic';
1420 1217 $mu_option4delete[]='booking_range_selection_type';
1421 1218 $default_options['booking_range_selection_days_count'] = '3';
1422 1219 $mu_option4delete[]='booking_range_selection_days_count';
1423 1220 $default_options['booking_range_selection_days_max_count_dynamic'] = 30;
@@ -1446,8 +1243,10 @@
1446 1243 $mu_option4delete[]='booking_change_over__is_excerpt_on_pages';
1447 1244 $default_options['booking_change_over__is_excerpt_on_pages'] = 'Off'; // FixIn: 8.9.4.10.
1448 1245 $mu_option4delete[]='booking_change_over__excerpt_on_pages';
1449 1246 $default_options['booking_change_over__excerpt_on_pages'] = ''; // FixIn: 8.9.4.10.
1247 + $mu_option4delete[]='booking_change_over__excerpt_bk_resources';
1248 + $default_options['booking_change_over__excerpt_bk_resources'] = ''; // FixIn: 10.16.4.1.
1450 1249
1451 1250
1452 1251 $default_options['booking_email_payment_request_adress'] = htmlspecialchars( '"Booking system" <' . get_option( 'admin_email' ) . '>' );
1453 1252 $default_options['booking_email_payment_request_subject'] = __( 'You need to make payment for this reservation', 'booking' );
@@ -1483,9 +1282,8 @@
1483 1282 $mu_option4delete[]='booking_unavailable_extra_days_in';
1484 1283 $default_options['booking_unavailable_extra_days_out'] = '';
1485 1284 $mu_option4delete[]='booking_unavailable_extra_days_out';
1486 1285
1487 - $default_options['booking_forms_extended'] = serialize( array() );
1488 1286 $default_options['booking_advanced_costs_values'] = serialize( array() );
1489 1287 $default_options['booking_is_resource_deposit_payment_active'] = 'On';
1490 1288 $mu_option4delete[]='booking_is_resource_deposit_payment_active';
1491 1289 $default_options['booking_advanced_costs_calc_fixed_cost_with_procents'] = 'Off';
@@ -1590,8 +1388,26 @@
1590 1388 // FixIn: 9.2.3.8.
1591 1389 $default_options['booking_super_admin_receive_regular_user_payments'] = 'Off';
1592 1390 $mu_option4delete[]='booking_super_admin_receive_regular_user_payments';
1593 1391 }
1392 +
1393 + /**
1394 + * Filters the complete Booking Calendar default-option registry.
1395 + *
1396 + * Edition modules may register missing-value defaults without placing their
1397 + * domain-specific option names in the shared Free-version implementation.
1398 + * Existing stored values continue to be preserved by the activation layer.
1399 + *
1400 + * @param array $default_options Default option names and values.
1401 + */
1402 + $default_options = apply_filters( 'wpbc_default_options', $default_options );
1403 +
1404 + /**
1405 + * Filters option names handled by the applicable MultiUser cleanup flow.
1406 + *
1407 + * @param array $mu_option4delete Option names registered for cleanup.
1408 + */
1409 + $mu_option4delete = apply_filters( 'wpbc_multiuser_options_for_delete', $mu_option4delete );
1594 1410
1595 1411
1596 1412 if ( ! $is_get_multiuser_general_options ) {
1597 1413