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

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

264 lines 8.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 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 ////////////////////////////////////////////////////////////////////////////////
18 // Internal plugin action hooks system
19 ////////////////////////////////////////////////////////////////////////////////
20 global $wpdev_bk_action, $wpdev_bk_filter;
21
22
23 function add_bk_filter($filter_type, $filter) {
24 global $wpdev_bk_filter;
25
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);
33
34 if ( is_array($wpdev_bk_filter) )
35
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 ) ) ;
45 }
46
47 function remove_bk_filter($filter_type, $filter) {
48 global $wpdev_bk_filter;
49
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 }
59
60 function apply_bk_filter($filter_type) {
61 global $wpdev_bk_filter;
62
63
64 $args = array();
65 for ( $a = 1; $a < func_num_args(); $a++ )
66 $args[] = func_get_arg($a);
67
68 if ( count($args) > 0 )
69 $value = $args[0];
70 else
71 $value = false;
72
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;
81 }
82
83
84 function make_bk_action($action_type) {
85 global $wpdev_bk_action;
86
87
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 }
99 }
100
101 function add_bk_action($action_type, $action) {
102 global $wpdev_bk_action;
103
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);
111
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);
120
121 else
122 $wpdev_bk_action = array( $action_type => array( $args ) ) ;
123 }
124
125 function remove_bk_action($action_type, $action) {
126 global $wpdev_bk_action;
127
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 }
136 }
137
138
139 function get_bk_option( $option, $default = false ) {
140
141 $u_value = apply_bk_filter('wpdev_bk_get_option', 'no-values' , $option, $default );
142 if ( $u_value !== 'no-values' ) return $u_value;
143
144 return get_option( $option, $default );
145 }
146
147 function update_bk_option ( $option, $newvalue ) {
148
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);
153 }
154
155 function delete_bk_option ( $option ) {
156
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 );
161 }
162
163 function add_bk_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
164
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 );
169 }
170
171
172 ////////////////////////////////////////////////////////////////////////////////
173 // Booking Meta Options - 'booking_options' IN 'wp_booking' TABLE
174 ////////////////////////////////////////////////////////////////////////////////
175
176 /**
177 * Update Booking Meta Option
178 *
179 * @param int $booking_id ID of the booking
180 * @param array $option_arr Associative array for saving into booking options
181 * Example 1: saving 'locale' => 'de_DE': [ 'locale' => 'de_DE' ],
182 * Example 2: [ 'paid' => '100.00', 'balance' => '90.00' ]
183 *
184 * @return array|object|stdClass[]|null
185 */
186 function wpbc_save_booking_meta_option( $booking_id, $option_arr ) {
187
188 global $wpdb;
189
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 );
192
193 if ( ! empty( $select_result ) ) {
194
195 $select_result = $select_result[0]->booking_options;
196
197 if ( is_null( $select_result ) ) { // NULL -> option was not defined yet for this booking row.
198 $exist_booking_option_arr = array();
199 } else {
200 $exist_booking_option_arr = maybe_unserialize( $select_result );
201 }
202
203 } else {
204 return false; // No booking with such ID
205 }
206
207 // Merge exist booking option array with new data
208 $new_booking_option_arr = array_merge(
209 $exist_booking_option_arr,
210 $option_arr
211 );
212
213 $serialized_booking_option_arr = maybe_serialize( $new_booking_option_arr );
214
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
221 debuge_error( 'Error saving to DB', __FILE__, __LINE__ );
222 return false;
223 }
224
225 return true;
226 }
227
228
229 /**
230 * Get Booking Meta Option
231 *
232 * @param int $booking_id ID of the booking
233 * @param false $option_name name of booking option or false (can be skipped) to return array of options
234 *
235 * @return array|mixed|string
236 */
237 function wpbc_get_booking_meta_option( $booking_id, $option_name = false ) {
238
239 global $wpdb;
240
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 );
243
244 $exist_booking_option_arr = array();
245
246 if ( ! empty( $select_result ) ) {
247
248 $select_result = $select_result[0]->booking_options;
249
250 if ( ! is_null( $select_result ) ) { // NULL -> chekc if option was not defined for this booking row.
251
252 $exist_booking_option_arr = maybe_unserialize( $select_result );
253
254 if (
255 ( ! empty( $option_name ) )
256 && ( ! empty( $exist_booking_option_arr[ $option_name ] ) )
257 ) {
258 return $exist_booking_option_arr[ $option_name ];
259 }
260 }
261 }
262
263 return $exist_booking_option_arr;
264 }