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-core.php +242 -140 10.1.3 → 11.9 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * @version 1.0
4 4 * @package Booking Calendar
@@ -11,162 +11,269 @@
11 11 *
12 12 * @modified 29.09.2015
13 13 */
14 14
15 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16 15
17 -////////////////////////////////////////////////////////////////////////////////
18 -// Internal plugin action hooks system
19 -////////////////////////////////////////////////////////////////////////////////
20 -global $wpdev_bk_action, $wpdev_bk_filter;
16 +if ( ! defined( 'ABSPATH' ) ) { // Exit if accessed directly.
17 + exit;
18 +}
21 19
20 +// ---------------------------------------------------------------------------------------------------------------------
21 +// Internal plugin action hooks system
22 +// ---------------------------------------------------------------------------------------------------------------------
23 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
24 +global $wpbc_bk_action, $wpbc_bk_filter;
25 +
26 +
27 +/**
28 + * Mark whether destructive Booking Calendar deactivation is running in this request.
29 + *
30 + * WordPress cannot unload plugin PHP after deactivate_plugins() is called. This
31 + * state lets already-loaded Pro and MultiUser callbacks avoid using deleted data.
32 + *
33 + * @param bool $is_deactivating Whether deactivation is in progress.
34 + */
35 +function wpbc_set_plugin_deactivation_state( $is_deactivating ) {
36 + global $wpbc_plugin_deactivation_in_progress;
37 +
38 + $wpbc_plugin_deactivation_in_progress = (bool) $is_deactivating;
39 +}
40 +
41 +
42 +/**
43 + * Check whether destructive Booking Calendar deactivation is running.
44 + *
45 + * @return bool
46 + */
47 +function wpbc_is_plugin_deactivation_in_progress() {
48 + global $wpbc_plugin_deactivation_in_progress;
49 +
50 + return ! empty( $wpbc_plugin_deactivation_in_progress );
51 +}
22 52
23 -function add_bk_filter($filter_type, $filter) {
24 - global $wpdev_bk_filter;
25 53
26 - $args = array();
27 - if ( is_array($filter) && 1 == count($filter) && is_object($filter[0]) ) // array(&$this)
28 - $args[] =& $filter[0];
29 - else
30 - $args[] = $filter;
31 - for ( $a = 2; $a < func_num_args(); $a++ )
32 - $args[] = func_get_arg($a);
54 +function add_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
55 + global $wpbc_bk_filter;
33 56
34 - if ( is_array($wpdev_bk_filter) )
57 + $args = array();
58 + if ( is_array( $filter ) && 1 == count( $filter ) && is_object( $filter[0] ) ) {
59 + $args[] =& $filter[0];
60 + } else {
61 + $args[] = $filter;
62 + }
63 + for ( $a = 2; $a < func_num_args(); $a++ ) {
64 + $args[] = func_get_arg( $a );
65 + }
35 66
36 - if ( isset($wpdev_bk_filter[$filter_type]) ) {
37 - if ( is_array($wpdev_bk_filter[$filter_type]) )
38 - $wpdev_bk_filter[$filter_type][]= $args;
39 - else
40 - $wpdev_bk_filter[$filter_type]= array($args);
41 - } else
42 - $wpdev_bk_filter[$filter_type]= array($args);
43 - else
44 - $wpdev_bk_filter = array( $filter_type => array( $args ) ) ;
67 + if ( is_array( $wpbc_bk_filter ) ) {
68 + if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) {
69 + if ( is_array( $wpbc_bk_filter[ $filter_type ] ) ) {
70 + $wpbc_bk_filter[ $filter_type ][] = $args;
71 + } else {
72 + $wpbc_bk_filter[ $filter_type ] = array( $args );
73 + }
74 + } else {
75 + $wpbc_bk_filter[ $filter_type ] = array( $args );
76 + }
77 + } else {
78 + $wpbc_bk_filter = array( $filter_type => array( $args ) );
79 + }
45 80 }
46 81
47 -function remove_bk_filter($filter_type, $filter) {
48 - global $wpdev_bk_filter;
82 +/**
83 + * Remove the first matching callback from an internal Booking Calendar filter.
84 + *
85 + * Registry entries must be deleted rather than replaced with null because the
86 + * same request may apply this filter again after a request-local override ends.
87 + *
88 + * @param string $filter_type Internal filter identifier.
89 + * @param callable $filter Callback registered with add_bk_filter().
90 + *
91 + * @return void
92 + */
93 +function remove_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
94 + global $wpbc_bk_filter;
95 +
96 + if (
97 + ! is_array( $wpbc_bk_filter )
98 + || empty( $wpbc_bk_filter[ $filter_type ] )
99 + || ! is_array( $wpbc_bk_filter[ $filter_type ] )
100 + ) {
101 + return;
102 + }
103 +
104 + foreach ( $wpbc_bk_filter[ $filter_type ] as $filter_index => $registered_filter ) {
105 + if ( ! is_array( $registered_filter ) || ! array_key_exists( 0, $registered_filter ) ) {
106 + continue;
107 + }
108 +
109 + // Preserve the legacy loose callback comparison for object-method arrays.
110 + if ( $registered_filter[0] == $filter ) {
111 + unset( $wpbc_bk_filter[ $filter_type ][ $filter_index ] );
112 + $wpbc_bk_filter[ $filter_type ] = array_values( $wpbc_bk_filter[ $filter_type ] );
113 +
114 + if ( empty( $wpbc_bk_filter[ $filter_type ] ) ) {
115 + unset( $wpbc_bk_filter[ $filter_type ] );
116 + }
117 +
118 + return;
119 + }
120 + }
121 +}
49 122
50 - if ( isset($wpdev_bk_filter[$filter_type]) ) {
51 - for ($i = 0; $i < count($wpdev_bk_filter[$filter_type]); $i++) {
52 - if ( $wpdev_bk_filter[$filter_type][$i][0] == $filter ) {
53 - $wpdev_bk_filter[$filter_type][$i] = null;
54 - return;
55 - }
56 - }
57 - }
58 -}
123 +/**
124 + * Apply callbacks registered for an internal Booking Calendar filter.
125 + *
126 + * Additional function arguments are forwarded to every registered callback.
127 + * The first additional argument is returned unchanged when no callback exists.
128 + *
129 + * @param string $filter_type Internal filter identifier.
130 + *
131 + * @return mixed Last callback result, the first supplied value, or false.
132 + */
133 +function apply_bk_filter( $filter_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
134 + global $wpbc_bk_filter;
59 135
60 -function apply_bk_filter($filter_type) {
61 - global $wpdev_bk_filter;
62 136
137 + $args = array();
138 + for ( $a = 1; $a < func_num_args(); $a++ ) {
139 + $args[] = func_get_arg( $a );
140 + }
63 141
64 - $args = array();
65 - for ( $a = 1; $a < func_num_args(); $a++ )
66 - $args[] = func_get_arg($a);
142 + if ( count( $args ) > 0 ) {
143 + $value = $args[0];
144 + } else {
145 + $value = false;
146 + }
67 147
68 - if ( count($args) > 0 )
69 - $value = $args[0];
70 - else
71 - $value = false;
148 + if (
149 + is_array( $wpbc_bk_filter )
150 + && ! empty( $wpbc_bk_filter[ $filter_type ] )
151 + && is_array( $wpbc_bk_filter[ $filter_type ] )
152 + ) {
153 + foreach ( $wpbc_bk_filter[ $filter_type ] as $filter ) {
154 + if ( ! is_array( $filter ) || empty( $filter ) ) {
155 + continue;
156 + }
157 +
158 + $filter_func = array_shift( $filter );
159 + $parameter = $args;
160 + $value = call_user_func_array( $filter_func, $parameter );
161 + }
162 + }
72 163
73 - if ( is_array($wpdev_bk_filter) )
74 - if ( isset($wpdev_bk_filter[$filter_type]) )
75 - foreach ($wpdev_bk_filter[$filter_type] as $filter) {
76 - $filter_func = array_shift($filter);
77 - $parameter = $args;
78 - $value = call_user_func_array($filter_func,$parameter );
79 - }
80 - return $value;
164 + return $value;
81 165 }
82 166
83 167
84 -function make_bk_action($action_type) {
85 - global $wpdev_bk_action;
168 +function make_bk_action( $action_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
169 + global $wpbc_bk_action;
86 170
171 + $args = array();
172 + for ( $a = 1; $a < func_num_args(); $a++ ) {
173 + $args[] = func_get_arg( $a );
174 + }
87 175
88 - $args = array();
89 - for ( $a = 1; $a < func_num_args(); $a++ )
90 - $args[] = func_get_arg($a);
91 -
92 - if ( is_array($wpdev_bk_action) )
93 - if ( isset($wpdev_bk_action[$action_type]) )
94 - foreach ($wpdev_bk_action[$action_type] as $action) {
95 - $action_func = array_shift($action);
96 - $parameter = $action;
97 - call_user_func_array($action_func,$args );
98 - }
176 + if ( is_array( $wpbc_bk_action ) ) {
177 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
178 + foreach ( $wpbc_bk_action[ $action_type ] as $action ) {
179 + $action_func = array_shift( $action );
180 + $parameter = $action;
181 + call_user_func_array( $action_func, $args );
182 + }
183 + }
184 + }
99 185 }
100 186
101 -function add_bk_action($action_type, $action) {
102 - global $wpdev_bk_action;
187 +function add_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
188 + global $wpbc_bk_action;
103 189
104 - $args = array();
105 - if ( is_array($action) && 1 == count($action) && is_object($action[0]) ) // array(&$this)
106 - $args[] =& $action[0];
107 - else
108 - $args[] = $action;
109 - for ( $a = 2; $a < func_num_args(); $a++ )
110 - $args[] = func_get_arg($a);
190 + $args = array();
191 + if ( is_array( $action ) && 1 == count( $action ) && is_object( $action[0] ) ) // array(&$this)
192 + {
193 + $args[] =& $action[0];
194 + } else {
195 + $args[] = $action;
196 + }
197 + for ( $a = 2; $a < func_num_args(); $a++ ) {
198 + $args[] = func_get_arg( $a );
199 + }
111 200
112 - if ( is_array($wpdev_bk_action) )
113 - if ( isset($wpdev_bk_action[$action_type]) ) {
114 - if ( is_array($wpdev_bk_action[$action_type]) )
115 - $wpdev_bk_action[$action_type][]= $args;
116 - else
117 - $wpdev_bk_action[$action_type]= array($args);
118 - } else
119 - $wpdev_bk_action[$action_type]= array($args);
201 + if ( is_array( $wpbc_bk_action ) ) {
202 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
203 + if ( is_array( $wpbc_bk_action[ $action_type ] ) ) {
204 + $wpbc_bk_action[ $action_type ][] = $args;
205 + } else {
206 + $wpbc_bk_action[ $action_type ] = array( $args );
207 + }
208 + } else {
209 + $wpbc_bk_action[ $action_type ] = array( $args );
210 + }
211 + } else {
212 + $wpbc_bk_action = array( $action_type => array( $args ) );
213 + }
214 +}
120 215
121 - else
122 - $wpdev_bk_action = array( $action_type => array( $args ) ) ;
123 -}
216 +function remove_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
217 + global $wpbc_bk_action;
124 218
125 -function remove_bk_action($action_type, $action) {
126 - global $wpdev_bk_action;
219 + $elements_count = count( $wpbc_bk_action[ $action_type ] );
220 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
221 + for ( $i = 0; $i < $elements_count; $i++ ) {
222 + if ( $wpbc_bk_action[ $action_type ][ $i ][0] == $action ) {
223 + $wpbc_bk_action[ $action_type ][ $i ] = null;
127 224
128 - if ( isset($wpdev_bk_action[$action_type]) ) {
129 - for ($i = 0; $i < count($wpdev_bk_action[$action_type]); $i++) {
130 - if ( $wpdev_bk_action[$action_type][$i][0] == $action ) {
131 - $wpdev_bk_action[$action_type][$i] = null;
132 - return;
133 - }
134 - }
135 - }
225 + return;
226 + }
227 + }
228 + }
136 229 }
137 230
138 231
139 -function get_bk_option( $option, $default = false ) {
232 +function get_bk_option( $option, $default = false ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
140 233
141 - $u_value = apply_bk_filter('wpdev_bk_get_option', 'no-values' , $option, $default );
142 - if ( $u_value !== 'no-values' ) return $u_value;
234 + global $wpbc__skip_get_bk_options;
143 235
144 - return get_option( $option, $default );
236 + if (
237 + ! empty( $wpbc__skip_get_bk_options )
238 + && is_array( $wpbc__skip_get_bk_options )
239 + && in_array( $option, $wpbc__skip_get_bk_options, true )
240 + ) {
241 + return $default;
242 + }
243 +
244 + $u_value = apply_bk_filter( 'wpdev_bk_get_option', 'no-values', $option, $default );
245 + if ( 'no-values' !== $u_value ) {
246 + return $u_value;
247 + }
248 + return get_option( $option, $default );
145 249 }
146 250
147 -function update_bk_option ( $option, $newvalue ) {
251 +function update_bk_option( $option, $newvalue ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
148 252
149 - $u_value = apply_bk_filter('wpdev_bk_update_option', 'no-values' , $option, $newvalue );
150 - if ( $u_value !== 'no-values' ) return $u_value;
151 -
152 - return update_option($option, $newvalue);
253 + $u_value = apply_bk_filter( 'wpdev_bk_update_option', 'no-values', $option, $newvalue );
254 + if ( 'no-values' !== $u_value ) {
255 + return $u_value;
256 + }
257 + return update_option( $option, $newvalue );
153 258 }
154 259
155 -function delete_bk_option ( $option ) {
260 +function delete_bk_option( $option ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
156 261
157 - $u_value = apply_bk_filter('wpdev_bk_delete_option', 'no-values' , $option );
158 - if ( $u_value !== 'no-values' ) return $u_value;
159 -
160 - return delete_option($option );
262 + $u_value = apply_bk_filter( 'wpdev_bk_delete_option', 'no-values', $option );
263 + if ( 'no-values' !== $u_value ) {
264 + return $u_value;
265 + }
266 + return delete_option( $option );
161 267 }
162 268
163 -function add_bk_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
269 +function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
164 270
165 - $u_value = apply_bk_filter('wpdev_bk_add_option', 'no-values' , $option, $value, $deprecated, $autoload );
166 - if ( $u_value !== 'no-values' ) return $u_value;
167 -
168 - return add_option( $option, $value , $deprecated , $autoload );
271 + $u_value = apply_bk_filter( 'wpdev_bk_add_option', 'no-values', $option, $value, $deprecated, $autoload );
272 + if ( 'no-values' !== $u_value ) {
273 + return $u_value;
274 + }
275 + return add_option( $option, $value, '', $autoload );
169 276 }
170 277
171 278
172 279 ////////////////////////////////////////////////////////////////////////////////
@@ -186,10 +293,10 @@
186 293 function wpbc_save_booking_meta_option( $booking_id, $option_arr ) {
187 294
188 295 global $wpdb;
189 296
190 - $sql_prepare = $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id );
191 - $select_result = $wpdb->get_results( $sql_prepare );
297 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
298 + $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
192 299
193 300 if ( ! empty( $select_result ) ) {
194 301
195 302 $select_result = $select_result[0]->booking_options;
@@ -198,32 +305,27 @@
198 305 $exist_booking_option_arr = array();
199 306 } else {
200 307 $exist_booking_option_arr = maybe_unserialize( $select_result );
201 308 }
202 -
203 309 } else {
204 - return false; // No booking with such ID
310 + return false; // No booking with such ID.
205 311 }
206 312
207 - // Merge exist booking option array with new data
313 + // Merge exist booking option array with new data.
208 314 $new_booking_option_arr = array_merge(
209 - $exist_booking_option_arr,
210 - $option_arr
211 - );
315 + $exist_booking_option_arr,
316 + $option_arr
317 + );
212 318
213 - $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
319 + $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
214 320
215 - $sql_prepare_update = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking SET booking_options = %s WHERE booking_id = %d"
216 - , $serialized_booking_option_arr
217 - , (int) $booking_id
218 - );
219 -
220 - if ( false === $wpdb->query( $sql_prepare_update ) ) { // Save to DB
321 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
322 + if ( false === $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}booking SET booking_options = %s WHERE booking_id = %d", $serialized_booking_option_arr, (int) $booking_id ) ) ) {
221 323 debuge_error( 'Error saving to DB', __FILE__, __LINE__ );
222 324 return false;
223 325 }
224 326
225 - return true;
327 + return true;
226 328 }
227 329
228 330
229 331 /**
@@ -237,28 +339,28 @@
237 339 function wpbc_get_booking_meta_option( $booking_id, $option_name = false ) {
238 340
239 341 global $wpdb;
240 342
241 - $sql_prepare = $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id );
242 - $select_result = $wpdb->get_results( $sql_prepare );
343 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
344 + $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
243 345
244 346 $exist_booking_option_arr = array();
245 -
347 +
246 348 if ( ! empty( $select_result ) ) {
247 349
248 350 $select_result = $select_result[0]->booking_options;
249 351
250 352 if ( ! is_null( $select_result ) ) { // NULL -> chekc if option was not defined for this booking row.
251 -
353 +
252 354 $exist_booking_option_arr = maybe_unserialize( $select_result );
253 355
254 - if (
255 - ( ! empty( $option_name ) )
256 - && ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
356 + if (
357 + ( ! empty( $option_name ) ) &&
358 + ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
257 359 ) {
258 360 return $exist_booking_option_arr[ $option_name ];
259 361 }
260 362 }
261 - }
262 -
363 + }
364 +
263 365 return $exist_booking_option_arr;
264 -}
366 +}