← All changes
|
integrations/wp-booking-calendar/includes/ajax-functions.php
+54
-0
5.7.2
→
6.0.4
View file →
| @@ -1,0 +1,54 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Ajax Functions | |
| 5 | + * | |
| 6 | + * @package AutomatorWP\BookingCalendar\Ajax_Functions | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Ajax function for selecting bookings | |
| 14 | + * | |
| 15 | + * @since 1.0.0 | |
| 16 | + */ | |
| 17 | +function automatorwp_wp_booking_calendar_ajax_get_bookings() { | |
| 18 | + // Security check | |
| 19 | + check_ajax_referer( 'automatorwp_admin', 'nonce' ); | |
| 20 | + | |
| 21 | + // Permissions check | |
| 22 | + if( ! current_user_can( automatorwp_get_manager_capability() ) ) { | |
| 23 | + wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'automatorwp' ) ); | |
| 24 | + } | |
| 25 | + | |
| 26 | + global $wpdb; | |
| 27 | + | |
| 28 | + // Pull back the search string | |
| 29 | + $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : ''; | |
| 30 | + | |
| 31 | + $results = array(); | |
| 32 | + | |
| 33 | + // Get the bookings | |
| 34 | + $bookings = $wpdb->get_results( $wpdb->prepare( | |
| 35 | + "SELECT booking_id, sort_date FROM {$wpdb->prefix}booking WHERE booking_id LIKE %s", | |
| 36 | + "%%{$search}%%" | |
| 37 | + ) ); | |
| 38 | + | |
| 39 | + foreach( $bookings as $booking ) { | |
| 40 | + $results[] = array( | |
| 41 | + 'id' => $booking->booking_id, | |
| 42 | + 'text' => 'Booking ' . $booking->booking_id . ': ' . $booking->sort_date, | |
| 43 | + ); | |
| 44 | + } | |
| 45 | + | |
| 46 | + // Prepend option none | |
| 47 | + $results = automatorwp_ajax_get_ajax_results_option_none( $results ); | |
| 48 | + | |
| 49 | + // Return our results | |
| 50 | + wp_send_json_success( $results ); | |
| 51 | + die; | |
| 52 | + | |
| 53 | +} | |
| 54 | +add_action( 'wp_ajax_automatorwp_wp_booking_calendar_get_bookings', 'automatorwp_wp_booking_calendar_ajax_get_bookings' ); | |