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 +140 -60 10.10.1 → 11.9 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * @version 1.0
4 4 * @package Booking Calendar
@@ -19,15 +19,42 @@
19 19
20 20 // ---------------------------------------------------------------------------------------------------------------------
21 21 // Internal plugin action hooks system
22 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 +}
23 52
24 -global $wpdev_bk_action, $wpdev_bk_filter;
25 53
54 +function add_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
55 + global $wpbc_bk_filter;
26 56
27 -function add_bk_filter( $filter_type, $filter ) {
28 - global $wpdev_bk_filter;
29 -
30 57 $args = array();
31 58 if ( is_array( $filter ) && 1 == count( $filter ) && is_object( $filter[0] ) ) {
32 59 $args[] =& $filter[0];
33 60 } else {
@@ -36,41 +63,78 @@
36 63 for ( $a = 2; $a < func_num_args(); $a++ ) {
37 64 $args[] = func_get_arg( $a );
38 65 }
39 66
40 - if ( is_array( $wpdev_bk_filter ) ) {
41 - if ( isset( $wpdev_bk_filter[ $filter_type ] ) ) {
42 - if ( is_array( $wpdev_bk_filter[ $filter_type ] ) ) {
43 - $wpdev_bk_filter[ $filter_type ][] = $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;
44 71 } else {
45 - $wpdev_bk_filter[ $filter_type ] = array( $args );
72 + $wpbc_bk_filter[ $filter_type ] = array( $args );
46 73 }
47 74 } else {
48 - $wpdev_bk_filter[ $filter_type ] = array( $args );
75 + $wpbc_bk_filter[ $filter_type ] = array( $args );
49 76 }
50 77 } else {
51 - $wpdev_bk_filter = array( $filter_type => array( $args ) );
78 + $wpbc_bk_filter = array( $filter_type => array( $args ) );
52 79 }
53 80 }
54 81
55 -function remove_bk_filter( $filter_type, $filter ) {
56 - 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 +}
57 122
58 - if ( isset( $wpdev_bk_filter[ $filter_type ] ) ) {
59 - for ( $i = 0; $i < count( $wpdev_bk_filter[ $filter_type ] ); $i++ ) {
60 - if ( $wpdev_bk_filter[ $filter_type ][ $i ][0] == $filter ) {
61 - $wpdev_bk_filter[ $filter_type ][ $i ] = null;
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;
62 135
63 - return;
64 - }
65 - }
66 - }
67 -}
68 136
69 -function apply_bk_filter( $filter_type ) {
70 - global $wpdev_bk_filter;
71 -
72 -
73 137 $args = array();
74 138 for ( $a = 1; $a < func_num_args(); $a++ ) {
75 139 $args[] = func_get_arg( $a );
76 140 }
@@ -80,24 +144,30 @@
80 144 } else {
81 145 $value = false;
82 146 }
83 147
84 - if ( is_array( $wpdev_bk_filter ) ) {
85 - if ( isset( $wpdev_bk_filter[ $filter_type ] ) ) {
86 - foreach ( $wpdev_bk_filter[ $filter_type ] as $filter ) {
87 - $filter_func = array_shift( $filter );
88 - $parameter = $args;
89 - $value = call_user_func_array( $filter_func, $parameter );
90 - }
91 - }
92 - }
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 + }
93 163
94 164 return $value;
95 165 }
96 166
97 167
98 -function make_bk_action( $action_type ) {
99 - global $wpdev_bk_action;
168 +function make_bk_action( $action_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
169 + global $wpbc_bk_action;
100 170
101 171 $args = array();
102 172 for ( $a = 1; $a < func_num_args(); $a++ ) {
103 173 $args[] = func_get_arg( $a );
@@ -102,11 +172,11 @@
102 172 for ( $a = 1; $a < func_num_args(); $a++ ) {
103 173 $args[] = func_get_arg( $a );
104 174 }
105 175
106 - if ( is_array( $wpdev_bk_action ) ) {
107 - if ( isset( $wpdev_bk_action[ $action_type ] ) ) {
108 - foreach ( $wpdev_bk_action[ $action_type ] as $action ) {
176 + if ( is_array( $wpbc_bk_action ) ) {
177 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
178 + foreach ( $wpbc_bk_action[ $action_type ] as $action ) {
109 179 $action_func = array_shift( $action );
110 180 $parameter = $action;
111 181 call_user_func_array( $action_func, $args );
112 182 }
@@ -113,10 +183,10 @@
113 183 }
114 184 }
115 185 }
116 186
117 -function add_bk_action( $action_type, $action ) {
118 - global $wpdev_bk_action;
187 +function add_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
188 + global $wpbc_bk_action;
119 189
120 190 $args = array();
121 191 if ( is_array( $action ) && 1 == count( $action ) && is_object( $action[0] ) ) // array(&$this)
122 192 {
@@ -127,31 +197,31 @@
127 197 for ( $a = 2; $a < func_num_args(); $a++ ) {
128 198 $args[] = func_get_arg( $a );
129 199 }
130 200
131 - if ( is_array( $wpdev_bk_action ) ) {
132 - if ( isset( $wpdev_bk_action[ $action_type ] ) ) {
133 - if ( is_array( $wpdev_bk_action[ $action_type ] ) ) {
134 - $wpdev_bk_action[ $action_type ][] = $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;
135 205 } else {
136 - $wpdev_bk_action[ $action_type ] = array( $args );
206 + $wpbc_bk_action[ $action_type ] = array( $args );
137 207 }
138 208 } else {
139 - $wpdev_bk_action[ $action_type ] = array( $args );
209 + $wpbc_bk_action[ $action_type ] = array( $args );
140 210 }
141 211 } else {
142 - $wpdev_bk_action = array( $action_type => array( $args ) );
212 + $wpbc_bk_action = array( $action_type => array( $args ) );
143 213 }
144 214 }
145 215
146 -function remove_bk_action( $action_type, $action ) {
147 - global $wpdev_bk_action;
216 +function remove_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
217 + global $wpbc_bk_action;
148 218
149 - $elements_count = count( $wpdev_bk_action[ $action_type ] );
150 - if ( isset( $wpdev_bk_action[ $action_type ] ) ) {
219 + $elements_count = count( $wpbc_bk_action[ $action_type ] );
220 + if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
151 221 for ( $i = 0; $i < $elements_count; $i++ ) {
152 - if ( $wpdev_bk_action[ $action_type ][ $i ][0] == $action ) {
153 - $wpdev_bk_action[ $action_type ][ $i ] = null;
222 + if ( $wpbc_bk_action[ $action_type ][ $i ][0] == $action ) {
223 + $wpbc_bk_action[ $action_type ][ $i ] = null;
154 224
155 225 return;
156 226 }
157 227 }
@@ -158,10 +228,20 @@
158 228 }
159 229 }
160 230
161 231
162 -function get_bk_option( $option, $default = false ) {
232 +function get_bk_option( $option, $default = false ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
163 233
234 + global $wpbc__skip_get_bk_options;
235 +
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 +
164 244 $u_value = apply_bk_filter( 'wpdev_bk_get_option', 'no-values', $option, $default );
165 245 if ( 'no-values' !== $u_value ) {
166 246 return $u_value;
167 247 }
@@ -167,9 +247,9 @@
167 247 }
168 248 return get_option( $option, $default );
169 249 }
170 250
171 -function update_bk_option( $option, $newvalue ) {
251 +function update_bk_option( $option, $newvalue ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
172 252
173 253 $u_value = apply_bk_filter( 'wpdev_bk_update_option', 'no-values', $option, $newvalue );
174 254 if ( 'no-values' !== $u_value ) {
175 255 return $u_value;
@@ -176,9 +256,9 @@
176 256 }
177 257 return update_option( $option, $newvalue );
178 258 }
179 259
180 -function delete_bk_option( $option ) {
260 +function delete_bk_option( $option ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
181 261
182 262 $u_value = apply_bk_filter( 'wpdev_bk_delete_option', 'no-values', $option );
183 263 if ( 'no-values' !== $u_value ) {
184 264 return $u_value;
@@ -185,9 +265,9 @@
185 265 }
186 266 return delete_option( $option );
187 267 }
188 268
189 -function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) {
269 +function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
190 270
191 271 $u_value = apply_bk_filter( 'wpdev_bk_add_option', 'no-values', $option, $value, $deprecated, $autoload );
192 272 if ( 'no-values' !== $u_value ) {
193 273 return $u_value;
@@ -282,5 +362,5 @@
282 362 }
283 363 }
284 364
285 365 return $exist_booking_option_arr;
286 -}
366 +}