PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
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 10.11.2 10.11.3 All 202 releases
booking / core / wpbc-core.php

wpbc-core.php in Booking Calendar 11.1, at core/wpbc-core.php

297 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Core Functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 29.09.2015
13 */
14
15
16 if ( ! defined( 'ABSPATH' ) ) { // Exit if accessed directly.
17 exit;
18 }
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 function add_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
28 global $wpbc_bk_filter;
29
30 $args = array();
31 if ( is_array( $filter ) && 1 == count( $filter ) && is_object( $filter[0] ) ) {
32 $args[] =& $filter[0];
33 } else {
34 $args[] = $filter;
35 }
36 for ( $a = 2; $a < func_num_args(); $a++ ) {
37 $args[] = func_get_arg( $a );
38 }
39
40 if ( is_array( $wpbc_bk_filter ) ) {
41 if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) {
42 if ( is_array( $wpbc_bk_filter[ $filter_type ] ) ) {
43 $wpbc_bk_filter[ $filter_type ][] = $args;
44 } else {
45 $wpbc_bk_filter[ $filter_type ] = array( $args );
46 }
47 } else {
48 $wpbc_bk_filter[ $filter_type ] = array( $args );
49 }
50 } else {
51 $wpbc_bk_filter = array( $filter_type => array( $args ) );
52 }
53 }
54
55 function remove_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
56 global $wpbc_bk_filter;
57
58 if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) {
59 for ( $i = 0; $i < count( $wpbc_bk_filter[ $filter_type ] ); $i++ ) {
60 if ( $wpbc_bk_filter[ $filter_type ][ $i ][0] == $filter ) {
61 $wpbc_bk_filter[ $filter_type ][ $i ] = null;
62
63 return;
64 }
65 }
66 }
67 }
68
69 function apply_bk_filter( $filter_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
70 global $wpbc_bk_filter;
71
72
73 $args = array();
74 for ( $a = 1; $a < func_num_args(); $a++ ) {
75 $args[] = func_get_arg( $a );
76 }
77
78 if ( count( $args ) > 0 ) {
79 $value = $args[0];
80 } else {
81 $value = false;
82 }
83
84 if ( is_array( $wpbc_bk_filter ) ) {
85 if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) {
86 foreach ( $wpbc_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 }
93
94 return $value;
95 }
96
97
98 function make_bk_action( $action_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
99 global $wpbc_bk_action;
100
101 $args = array();
102 for ( $a = 1; $a < func_num_args(); $a++ ) {
103 $args[] = func_get_arg( $a );
104 }
105
106 if ( is_array( $wpbc_bk_action ) ) {
107 if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
108 foreach ( $wpbc_bk_action[ $action_type ] as $action ) {
109 $action_func = array_shift( $action );
110 $parameter = $action;
111 call_user_func_array( $action_func, $args );
112 }
113 }
114 }
115 }
116
117 function add_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
118 global $wpbc_bk_action;
119
120 $args = array();
121 if ( is_array( $action ) && 1 == count( $action ) && is_object( $action[0] ) ) // array(&$this)
122 {
123 $args[] =& $action[0];
124 } else {
125 $args[] = $action;
126 }
127 for ( $a = 2; $a < func_num_args(); $a++ ) {
128 $args[] = func_get_arg( $a );
129 }
130
131 if ( is_array( $wpbc_bk_action ) ) {
132 if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
133 if ( is_array( $wpbc_bk_action[ $action_type ] ) ) {
134 $wpbc_bk_action[ $action_type ][] = $args;
135 } else {
136 $wpbc_bk_action[ $action_type ] = array( $args );
137 }
138 } else {
139 $wpbc_bk_action[ $action_type ] = array( $args );
140 }
141 } else {
142 $wpbc_bk_action = array( $action_type => array( $args ) );
143 }
144 }
145
146 function remove_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
147 global $wpbc_bk_action;
148
149 $elements_count = count( $wpbc_bk_action[ $action_type ] );
150 if ( isset( $wpbc_bk_action[ $action_type ] ) ) {
151 for ( $i = 0; $i < $elements_count; $i++ ) {
152 if ( $wpbc_bk_action[ $action_type ][ $i ][0] == $action ) {
153 $wpbc_bk_action[ $action_type ][ $i ] = null;
154
155 return;
156 }
157 }
158 }
159 }
160
161
162 function get_bk_option( $option, $default = false ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
163
164 global $wpbc__skip_get_bk_options;
165
166 if (
167 ! empty( $wpbc__skip_get_bk_options )
168 && is_array( $wpbc__skip_get_bk_options )
169 && in_array( $option, $wpbc__skip_get_bk_options, true )
170 ) {
171 return $default;
172 }
173
174 $u_value = apply_bk_filter( 'wpdev_bk_get_option', 'no-values', $option, $default );
175 if ( 'no-values' !== $u_value ) {
176 return $u_value;
177 }
178 return get_option( $option, $default );
179 }
180
181 function update_bk_option( $option, $newvalue ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
182
183 $u_value = apply_bk_filter( 'wpdev_bk_update_option', 'no-values', $option, $newvalue );
184 if ( 'no-values' !== $u_value ) {
185 return $u_value;
186 }
187 return update_option( $option, $newvalue );
188 }
189
190 function delete_bk_option( $option ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
191
192 $u_value = apply_bk_filter( 'wpdev_bk_delete_option', 'no-values', $option );
193 if ( 'no-values' !== $u_value ) {
194 return $u_value;
195 }
196 return delete_option( $option );
197 }
198
199 function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
200
201 $u_value = apply_bk_filter( 'wpdev_bk_add_option', 'no-values', $option, $value, $deprecated, $autoload );
202 if ( 'no-values' !== $u_value ) {
203 return $u_value;
204 }
205 return add_option( $option, $value, '', $autoload );
206 }
207
208
209 ////////////////////////////////////////////////////////////////////////////////
210 // Booking Meta Options - 'booking_options' IN 'wp_booking' TABLE
211 ////////////////////////////////////////////////////////////////////////////////
212
213 /**
214 * Update Booking Meta Option
215 *
216 * @param int $booking_id ID of the booking
217 * @param array $option_arr Associative array for saving into booking options
218 * Example 1: saving 'locale' => 'de_DE': [ 'locale' => 'de_DE' ],
219 * Example 2: [ 'paid' => '100.00', 'balance' => '90.00' ]
220 *
221 * @return array|object|stdClass[]|null
222 */
223 function wpbc_save_booking_meta_option( $booking_id, $option_arr ) {
224
225 global $wpdb;
226
227 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
228 $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
229
230 if ( ! empty( $select_result ) ) {
231
232 $select_result = $select_result[0]->booking_options;
233
234 if ( is_null( $select_result ) ) { // NULL -> option was not defined yet for this booking row.
235 $exist_booking_option_arr = array();
236 } else {
237 $exist_booking_option_arr = maybe_unserialize( $select_result );
238 }
239 } else {
240 return false; // No booking with such ID.
241 }
242
243 // Merge exist booking option array with new data.
244 $new_booking_option_arr = array_merge(
245 $exist_booking_option_arr,
246 $option_arr
247 );
248
249 $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
250
251 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
252 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 ) ) ) {
253 debuge_error( 'Error saving to DB', __FILE__, __LINE__ );
254 return false;
255 }
256
257 return true;
258 }
259
260
261 /**
262 * Get Booking Meta Option
263 *
264 * @param int $booking_id ID of the booking
265 * @param false $option_name name of booking option or false (can be skipped) to return array of options
266 *
267 * @return array|mixed|string
268 */
269 function wpbc_get_booking_meta_option( $booking_id, $option_name = false ) {
270
271 global $wpdb;
272
273 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
274 $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
275
276 $exist_booking_option_arr = array();
277
278 if ( ! empty( $select_result ) ) {
279
280 $select_result = $select_result[0]->booking_options;
281
282 if ( ! is_null( $select_result ) ) { // NULL -> chekc if option was not defined for this booking row.
283
284 $exist_booking_option_arr = maybe_unserialize( $select_result );
285
286 if (
287 ( ! empty( $option_name ) ) &&
288 ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
289 ) {
290 return $exist_booking_option_arr[ $option_name ];
291 }
292 }
293 }
294
295 return $exist_booking_option_arr;
296 }
297