PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
← All changes | core/customers/customer.php +72 -6 1.0.10 → 1.0.64 View file →
@@ -46,8 +46,9 @@
46 46 'last_name' => '',
47 47 'email' => '',
48 48 'phone' => '',
49 49 'password' => '',
50 + 'quantity' => []
50 51 ];
51 52
52 53 /**
53 54 * Customer constructor
@@ -149,8 +150,46 @@
149 150 return $user->user_pass;
150 151 }
151 152
152 153 /**
154 + * Get quantity
155 + *
156 + * @return array
157 + */
158 + public function get_quantity() {
159 + $all_quantity = $this->get_prop( 'quantity' );
160 + $quantities = [];
161 + if ( is_array( $all_quantity ) ){
162 + foreach( $all_quantity as $key => $quantity){
163 + $quantities[$key] = $quantity;
164 + }
165 + }
166 + return $quantities;
167 +
168 + }
169 +
170 + /**
171 + * Get Attendees
172 + *
173 + * @return array
174 + */
175 + public function get_attendees() {
176 + $all_attendees = $this->get_prop( 'attendees' );
177 + $attendees = [];
178 +
179 + if ( is_array( $all_attendees ) ) {
180 + foreach( $all_attendees as $key => $attendee ) {
181 + $attendees[] = [
182 + 'name' => $attendee['name'],
183 + 'email' => $attendee['email']
184 + ];
185 + }
186 + }
187 + return $attendees;
188 +
189 + }
190 +
191 + /**
153 192 * Get prop
154 193 *
155 194 * @param string
156 195 *
@@ -168,12 +207,12 @@
168 207 * @return string
169 208 */
170 209 public function get_metadata( $prop = '' ) {
171 210 if( $prop == 'first_name' || $prop == 'last_name' ) {
172 - $meta_key = $prop;
211 + $meta_key = $prop;
173 212 } else {
174 213 $meta_key = $this->meta_prefix . $prop;
175 - }
214 + }
176 215
177 216 return get_user_meta( $this->id, $meta_key, true );
178 217
179 218 }
@@ -209,9 +248,9 @@
209 248 public function save_metadata() {
210 249 foreach ( $this->data as $key => $value ) {
211 250 // Prepare meta key.
212 251 if( $key == 'first_name' || $key == 'last_name' ) {
213 - $meta_key = $key;
252 + $meta_key = $key;
214 253 } else {
215 254 $meta_key = $this->meta_prefix . $key;
216 255 }
217 256
@@ -247,8 +286,16 @@
247 286 'user_login' => $this->data['email'],
248 287 'user_email' => $this->data['email'],
249 288 ];
250 289
290 + $user_data = get_user_by( 'email', $this->data['email'] );
291 +
292 + if ( $user_data && ! in_array( 'timetics-customer', $user_data->roles, true ) ) {
293 + $user_data->add_role( 'timetics-customer' );
294 +
295 + return $user_data->ID;
296 + }
297 +
251 298 if ( $this->id ) {
252 299 $args['ID'] = $this->id;
253 300 $args['user_pass'] = $this->data['password'];
254 301 $customer_id = wp_update_user( $args );
@@ -273,8 +320,9 @@
273 320 * @return bool
274 321 */
275 322 public function delete() {
276 323 require_once ABSPATH . 'wp-admin/includes/user.php';
324 + $user = get_userdata( $this->id );
277 325
278 326 // Get all bookings for this customer.
279 327 $bookings = $this->get_bookings();
280 328
@@ -283,8 +331,14 @@
283 331 $booking = new Booking( $booking );
284 332 $booking->delete();
285 333 }
286 334
335 + if ( count( $user->roles ) > 1 ) {
336 + $user->remove_role('timetics-customer');
337 +
338 + return true;
339 + }
340 +
287 341 return wp_delete_user( $this->id );
288 342 }
289 343
290 344 /**
@@ -307,14 +361,19 @@
307 361
308 362 if ( email_exists( $args['email'] ) ) {
309 363 $user = get_user_by( 'email', $args['email'] );
310 364
311 - if ( ! $this->is_customer() ) {
365 + if ( $user && ! in_array( 'timetics-customer', $user->roles, true ) ) {
312 366 $user->add_role( 'timetics-customer' );
367 + $this->set_id( $user->ID );
368 +
369 + return $user->ID;
313 370 }
371 +
314 372 $this->set_id( $user->ID );
315 373 $this->set_props( $args );
316 - $this->save_metadata();
374 + $this->save_metadata( $args );
375 +
317 376 } else {
318 377 $this->set_props( $args );
319 378 $this->save();
320 379 }
@@ -355,12 +414,19 @@
355 414 *
356 415 * @return WP_Query
357 416 */
358 417 private function booking_query() {
418 + // Not tied to "default_booking_status" (that's what status a NEW
419 + // booking starts in, not which bookings count here) — otherwise an
420 + // approved booking can vanish from the customer's count/history the
421 + // moment it's approved, on any site where new bookings default to
422 + // pending. See core/reports/api-report.php for the same fix.
423 + $counted_statuses = apply_filters( 'timetics/report/counted_statuses', [ 'approved', 'completed' ] );
424 +
359 425 $query = new \WP_Query(
360 426 [
361 427 'post_type' => 'timetics-booking',
362 - 'post_status' => 'completed',
428 + 'post_status' => $counted_statuses,
363 429 // @codingStandardsIgnoreStart
364 430 'meta_key' => '_tt_booking_customer',
365 431 'meta_value' => $this->id,
366 432 // @codingStandardsIgnoreEnd