| @@ -1,0 +1,63 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\BookingPress\Functions | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Get the related WordPress user ID from a BookingPress customer ID. | |
| 14 | + * | |
| 15 | + * @since 1.0.0 | |
| 16 | + * | |
| 17 | + * @param int $customer_id BookingPress customer ID. | |
| 18 | + * | |
| 19 | + * @return int WordPress user ID or 0 when there is no linked account. | |
| 20 | + */ | |
| 21 | +function automatorwp_bookingpress_get_wp_user_id_from_customer_id( $customer_id ) { | |
| 22 | + | |
| 23 | + global $wpdb; | |
| 24 | + | |
| 25 | + $customer_id = absint( $customer_id ); | |
| 26 | + | |
| 27 | + if( empty( $customer_id ) ) { | |
| 28 | + return 0; | |
| 29 | + } | |
| 30 | + | |
| 31 | + $customer_table = $wpdb->prefix . 'bookingpress_customers'; | |
| 32 | + $wp_user_id = $wpdb->get_var( | |
| 33 | + $wpdb->prepare( | |
| 34 | + "SELECT bookingpress_wpuser_id FROM {$customer_table} WHERE bookingpress_customer_id = %d", | |
| 35 | + $customer_id | |
| 36 | + ) | |
| 37 | + ); | |
| 38 | + | |
| 39 | + return absint( $wp_user_id ); | |
| 40 | + | |
| 41 | +} | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * Get BookingPress customer data | |
| 45 | + * | |
| 46 | + * @since 1.0.0 | |
| 47 | + * | |
| 48 | + * @return array|false | |
| 49 | + */ | |
| 50 | +function automatorwp_bookingpress_get_customer_data( $customer_id ) { | |
| 51 | + | |
| 52 | + global $wpdb; | |
| 53 | + | |
| 54 | + // Empty if no ID provided | |
| 55 | + if( absint( $customer_id ) === 0 ) { | |
| 56 | + return ''; | |
| 57 | + } | |
| 58 | + | |
| 59 | + $customer = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}bookingpress_customers WHERE bookingpress_customer_id = {$customer_id}" ); | |
| 60 | + | |
| 61 | + return $customer; | |
| 62 | + | |
| 63 | +} | |