PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
← All changes | core/wpbc-core.php +198 -139 10.1.311.8.3 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * @version 1.0
4 4 * @package Booking Calendar
@@ -11,162 +11,226 @@
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 +function remove_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
83 + global $wpbc_bk_filter;
49 84
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 - }
85 + if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) {
86 + for ( $i = 0; $i < count( $wpbc_bk_filter[ $filter_type ] ); $i++ ) {
87 + if ( $wpbc_bk_filter[ $filter_type ][ $i ][0] == $filter ) {
88 + $wpbc_bk_filter[ $filter_type ][ $i ] = null;
89 +
90 + return;
91 + }
92 + }
93 + }
58 94 }
59 95
60 -function apply_bk_filter($filter_type) {
61 - global $wpdev_bk_filter;
96 +function apply_bk_filter( $filter_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
97 + global $wpbc_bk_filter;
62 98
63 99
64 - $args = array();
65 - for ( $a = 1; $a < func_num_args(); $a++ )
66 - $args[] = func_get_arg($a);
100 + $args = array();
101 + for ( $a = 1; $a < func_num_args(); $a++ ) {
102 + $args[] = func_get_arg( $a );
103 + }
67 104
68 - if ( count($args) > 0 )
69 - $value = $args[0];
70 - else
71 - $value = false;
105 + if ( count( $args ) > 0 ) {
106 + $value = $args[0];
107 + } else {
108 + $value = false;
109 + }
72 110
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;
111 + if ( is_array( $wpbc_bk_filter ) ) {
112 + if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) {
113 + foreach ( $wpbc_bk_filter[ $filter_type ] as $filter ) {
114 + $filter_func = array_shift( $filter );
115 + $parameter = $args;
116 + $value = call_user_func_array( $filter_func, $parameter );
117 + }
118 + }
119 + }
120 +
121 + return $value;
81 122 }
82 123
83 124
84 -function make_bk_action($action_type) {
85 - global $wpdev_bk_action;
125 +function make_bk_action( $action_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
126 + global $wpbc_bk_action;
86 127
128 + $args = array();
129 + for ( $a = 1; $a < func_num_args(); $a++ ) {
130 + $args[] = func_get_arg( $a );
131 + }
87 132
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 - }
133 + if ( is_array( $wpbc_bk_action ) ) {
134 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
135 + foreach ( $wpbc_bk_action[ $action_type ] as $action ) {
136 + $action_func = array_shift( $action );
137 + $parameter = $action;
138 + call_user_func_array( $action_func, $args );
139 + }
140 + }
141 + }
99 142 }
100 143
101 -function add_bk_action($action_type, $action) {
102 - global $wpdev_bk_action;
144 +function add_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
145 + global $wpbc_bk_action;
103 146
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);
147 + $args = array();
148 + if ( is_array( $action ) && 1 == count( $action ) && is_object( $action[0] ) ) // array(&$this)
149 + {
150 + $args[] =& $action[0];
151 + } else {
152 + $args[] = $action;
153 + }
154 + for ( $a = 2; $a < func_num_args(); $a++ ) {
155 + $args[] = func_get_arg( $a );
156 + }
111 157
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);
158 + if ( is_array( $wpbc_bk_action ) ) {
159 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
160 + if ( is_array( $wpbc_bk_action[ $action_type ] ) ) {
161 + $wpbc_bk_action[ $action_type ][] = $args;
162 + } else {
163 + $wpbc_bk_action[ $action_type ] = array( $args );
164 + }
165 + } else {
166 + $wpbc_bk_action[ $action_type ] = array( $args );
167 + }
168 + } else {
169 + $wpbc_bk_action = array( $action_type => array( $args ) );
170 + }
171 +}
120 172
121 - else
122 - $wpdev_bk_action = array( $action_type => array( $args ) ) ;
123 -}
173 +function remove_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
174 + global $wpbc_bk_action;
124 175
125 -function remove_bk_action($action_type, $action) {
126 - global $wpdev_bk_action;
176 + $elements_count = count( $wpbc_bk_action[ $action_type ] );
177 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
178 + for ( $i = 0; $i < $elements_count; $i++ ) {
179 + if ( $wpbc_bk_action[ $action_type ][ $i ][0] == $action ) {
180 + $wpbc_bk_action[ $action_type ][ $i ] = null;
127 181
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 - }
182 + return;
183 + }
184 + }
185 + }
136 186 }
137 187
138 188
139 -function get_bk_option( $option, $default = false ) {
189 +function get_bk_option( $option, $default = false ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
140 190
141 - $u_value = apply_bk_filter('wpdev_bk_get_option', 'no-values' , $option, $default );
142 - if ( $u_value !== 'no-values' ) return $u_value;
191 + global $wpbc__skip_get_bk_options;
143 192
144 - return get_option( $option, $default );
193 + if (
194 + ! empty( $wpbc__skip_get_bk_options )
195 + && is_array( $wpbc__skip_get_bk_options )
196 + && in_array( $option, $wpbc__skip_get_bk_options, true )
197 + ) {
198 + return $default;
199 + }
200 +
201 + $u_value = apply_bk_filter( 'wpdev_bk_get_option', 'no-values', $option, $default );
202 + if ( 'no-values' !== $u_value ) {
203 + return $u_value;
204 + }
205 + return get_option( $option, $default );
145 206 }
146 207
147 -function update_bk_option ( $option, $newvalue ) {
208 +function update_bk_option( $option, $newvalue ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
148 209
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);
210 + $u_value = apply_bk_filter( 'wpdev_bk_update_option', 'no-values', $option, $newvalue );
211 + if ( 'no-values' !== $u_value ) {
212 + return $u_value;
213 + }
214 + return update_option( $option, $newvalue );
153 215 }
154 216
155 -function delete_bk_option ( $option ) {
217 +function delete_bk_option( $option ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
156 218
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 );
219 + $u_value = apply_bk_filter( 'wpdev_bk_delete_option', 'no-values', $option );
220 + if ( 'no-values' !== $u_value ) {
221 + return $u_value;
222 + }
223 + return delete_option( $option );
161 224 }
162 225
163 -function add_bk_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
226 +function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
164 227
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 );
228 + $u_value = apply_bk_filter( 'wpdev_bk_add_option', 'no-values', $option, $value, $deprecated, $autoload );
229 + if ( 'no-values' !== $u_value ) {
230 + return $u_value;
231 + }
232 + return add_option( $option, $value, '', $autoload );
169 233 }
170 234
171 235
172 236 ////////////////////////////////////////////////////////////////////////////////
@@ -186,10 +250,10 @@
186 250 function wpbc_save_booking_meta_option( $booking_id, $option_arr ) {
187 251
188 252 global $wpdb;
189 253
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 );
254 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
255 + $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
192 256
193 257 if ( ! empty( $select_result ) ) {
194 258
195 259 $select_result = $select_result[0]->booking_options;
@@ -198,32 +262,27 @@
198 262 $exist_booking_option_arr = array();
199 263 } else {
200 264 $exist_booking_option_arr = maybe_unserialize( $select_result );
201 265 }
202 -
203 266 } else {
204 - return false; // No booking with such ID
267 + return false; // No booking with such ID.
205 268 }
206 269
207 - // Merge exist booking option array with new data
270 + // Merge exist booking option array with new data.
208 271 $new_booking_option_arr = array_merge(
209 - $exist_booking_option_arr,
210 - $option_arr
211 - );
272 + $exist_booking_option_arr,
273 + $option_arr
274 + );
212 275
213 - $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
276 + $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
214 277
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
278 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
279 + 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 280 debuge_error( 'Error saving to DB', __FILE__, __LINE__ );
222 281 return false;
223 282 }
224 283
225 - return true;
284 + return true;
226 285 }
227 286
228 287
229 288 /**
@@ -237,28 +296,28 @@
237 296 function wpbc_get_booking_meta_option( $booking_id, $option_name = false ) {
238 297
239 298 global $wpdb;
240 299
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 );
300 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
301 + $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
243 302
244 303 $exist_booking_option_arr = array();
245 -
304 +
246 305 if ( ! empty( $select_result ) ) {
247 306
248 307 $select_result = $select_result[0]->booking_options;
249 308
250 309 if ( ! is_null( $select_result ) ) { // NULL -> chekc if option was not defined for this booking row.
251 -
310 +
252 311 $exist_booking_option_arr = maybe_unserialize( $select_result );
253 312
254 - if (
255 - ( ! empty( $option_name ) )
256 - && ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
313 + if (
314 + ( ! empty( $option_name ) ) &&
315 + ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
257 316 ) {
258 317 return $exist_booking_option_arr[ $option_name ];
259 318 }
260 319 }
261 - }
262 -
320 + }
321 +
263 322 return $exist_booking_option_arr;
264 -}
323 +}