PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
11.9 11.8.4 11.8.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 All 205 releases
booking / includes / booking-resource-selector / ajax / booking-resource-selector__resolve.php

booking-resource-selector__resolve.php in Booking Calendar 11.7, at includes/booking-resource-selector/ajax/booking-resource-selector__resolve.php

53 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Public AJAX endpoint for resolving Booking Resource selector stages.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Resolve a Booking Resource selection and return the native form stage.
14 *
15 * The endpoint is read-only. It verifies the public nonce and signed shortcode
16 * configuration, then rebuilds the current resource catalogue before render.
17 *
18 * @return void Terminates with a JSON response.
19 */
20 function wpbc_booking_resource_selector_ajax_resolve() {
21 if ( false === check_ajax_referer( 'wpbc_booking_resource_selector_ajax', 'nonce', false ) ) {
22 wp_send_json_error( array( 'message' => __( 'Security check failed. Reload the page and try again.', 'booking' ) ), 403 );
23 }
24
25 $config_token = isset( $_POST['config_token'] ) && ! is_array( $_POST['config_token'] ) ? sanitize_text_field( wp_unslash( $_POST['config_token'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
26 $config = wpbc_booking_resource_selector_decode_config( $config_token );
27 if ( is_wp_error( $config ) ) {
28 wp_send_json_error(
29 array(
30 'message' => $config->get_error_message(),
31 'code' => $config->get_error_code(),
32 ),
33 400
34 );
35 }
36
37 $resource_id = isset( $_POST['resource_id'] ) && ! is_array( $_POST['resource_id'] ) ? absint( wp_unslash( $_POST['resource_id'] ) ) : 0;
38 $result = wpbc_booking_resource_selector_resolve_stage( $config, $resource_id, 0 < $resource_id );
39 if ( is_wp_error( $result ) ) {
40 wp_send_json_error(
41 array(
42 'message' => $result->get_error_message(),
43 'code' => $result->get_error_code(),
44 ),
45 400
46 );
47 }
48
49 wp_send_json_success( $result );
50 }
51 add_action( 'wp_ajax_nopriv_WPBC_AJX_BOOKING_RESOURCE_SELECTOR_RESOLVE', 'wpbc_booking_resource_selector_ajax_resolve' );
52 add_action( 'wp_ajax_WPBC_AJX_BOOKING_RESOURCE_SELECTOR_RESOLVE', 'wpbc_booking_resource_selector_ajax_resolve' );
53