PluginProbe
Booking Calendar / 10.11.2
Booking Calendar v10.11.2
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 10.11.2, at core/wpbc-core.php

286 lines 8.2 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
24 global $wpdev_bk_action, $wpdev_bk_filter;
25
26
27 function add_bk_filter( $filter_type, $filter ) {
28 global $wpdev_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( $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;
44 } else {
45 $wpdev_bk_filter[ $filter_type ] = array( $args );
46 }
47 } else {
48 $wpdev_bk_filter[ $filter_type ] = array( $args );
49 }
50 } else {
51 $wpdev_bk_filter = array( $filter_type => array( $args ) );
52 }
53 }
54
55 function remove_bk_filter( $filter_type, $filter ) {
56 global $wpdev_bk_filter;
57
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;
62
63 return;
64 }
65 }
66 }
67 }
68
69 function apply_bk_filter( $filter_type ) {
70 global $wpdev_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( $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 }
93
94 return $value;
95 }
96
97
98 function make_bk_action( $action_type ) {
99 global $wpdev_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( $wpdev_bk_action ) ) {
107 if ( isset( $wpdev_bk_action[ $action_type ] ) ) {
108 foreach ( $wpdev_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 ) {
118 global $wpdev_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( $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;
135 } else {
136 $wpdev_bk_action[ $action_type ] = array( $args );
137 }
138 } else {
139 $wpdev_bk_action[ $action_type ] = array( $args );
140 }
141 } else {
142 $wpdev_bk_action = array( $action_type => array( $args ) );
143 }
144 }
145
146 function remove_bk_action( $action_type, $action ) {
147 global $wpdev_bk_action;
148
149 $elements_count = count( $wpdev_bk_action[ $action_type ] );
150 if ( isset( $wpdev_bk_action[ $action_type ] ) ) {
151 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;
154
155 return;
156 }
157 }
158 }
159 }
160
161
162 function get_bk_option( $option, $default = false ) {
163
164 $u_value = apply_bk_filter( 'wpdev_bk_get_option', 'no-values', $option, $default );
165 if ( 'no-values' !== $u_value ) {
166 return $u_value;
167 }
168 return get_option( $option, $default );
169 }
170
171 function update_bk_option( $option, $newvalue ) {
172
173 $u_value = apply_bk_filter( 'wpdev_bk_update_option', 'no-values', $option, $newvalue );
174 if ( 'no-values' !== $u_value ) {
175 return $u_value;
176 }
177 return update_option( $option, $newvalue );
178 }
179
180 function delete_bk_option( $option ) {
181
182 $u_value = apply_bk_filter( 'wpdev_bk_delete_option', 'no-values', $option );
183 if ( 'no-values' !== $u_value ) {
184 return $u_value;
185 }
186 return delete_option( $option );
187 }
188
189 function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) {
190
191 $u_value = apply_bk_filter( 'wpdev_bk_add_option', 'no-values', $option, $value, $deprecated, $autoload );
192 if ( 'no-values' !== $u_value ) {
193 return $u_value;
194 }
195 return add_option( $option, $value, '', $autoload );
196 }
197
198
199 ////////////////////////////////////////////////////////////////////////////////
200 // Booking Meta Options - 'booking_options' IN 'wp_booking' TABLE
201 ////////////////////////////////////////////////////////////////////////////////
202
203 /**
204 * Update Booking Meta Option
205 *
206 * @param int $booking_id ID of the booking
207 * @param array $option_arr Associative array for saving into booking options
208 * Example 1: saving 'locale' => 'de_DE': [ 'locale' => 'de_DE' ],
209 * Example 2: [ 'paid' => '100.00', 'balance' => '90.00' ]
210 *
211 * @return array|object|stdClass[]|null
212 */
213 function wpbc_save_booking_meta_option( $booking_id, $option_arr ) {
214
215 global $wpdb;
216
217 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
218 $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
219
220 if ( ! empty( $select_result ) ) {
221
222 $select_result = $select_result[0]->booking_options;
223
224 if ( is_null( $select_result ) ) { // NULL -> option was not defined yet for this booking row.
225 $exist_booking_option_arr = array();
226 } else {
227 $exist_booking_option_arr = maybe_unserialize( $select_result );
228 }
229 } else {
230 return false; // No booking with such ID.
231 }
232
233 // Merge exist booking option array with new data.
234 $new_booking_option_arr = array_merge(
235 $exist_booking_option_arr,
236 $option_arr
237 );
238
239 $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
240
241 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
242 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 ) ) ) {
243 debuge_error( 'Error saving to DB', __FILE__, __LINE__ );
244 return false;
245 }
246
247 return true;
248 }
249
250
251 /**
252 * Get Booking Meta Option
253 *
254 * @param int $booking_id ID of the booking
255 * @param false $option_name name of booking option or false (can be skipped) to return array of options
256 *
257 * @return array|mixed|string
258 */
259 function wpbc_get_booking_meta_option( $booking_id, $option_name = false ) {
260
261 global $wpdb;
262
263 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
264 $select_result = $wpdb->get_results( $wpdb->prepare( "SELECT booking_options FROM {$wpdb->prefix}booking WHERE booking_id = %d", (int) $booking_id ) );
265
266 $exist_booking_option_arr = array();
267
268 if ( ! empty( $select_result ) ) {
269
270 $select_result = $select_result[0]->booking_options;
271
272 if ( ! is_null( $select_result ) ) { // NULL -> chekc if option was not defined for this booking row.
273
274 $exist_booking_option_arr = maybe_unserialize( $select_result );
275
276 if (
277 ( ! empty( $option_name ) ) &&
278 ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
279 ) {
280 return $exist_booking_option_arr[ $option_name ];
281 }
282 }
283 }
284
285 return $exist_booking_option_arr;
286 }