PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
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 10.11 All 204 releases
booking / includes / booking_modes_v3 / ajax / booking_mode_quickstart.php

booking_mode_quickstart.php in Booking Calendar 11.8.4, at includes/booking_modes_v3/ajax/booking_mode_quickstart.php

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AJAX boundary for explicit Booking Mode QuickStart operations.
4 *
5 * @package Booking Calendar
6 * @since 11.5.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Validate and run one owner-scoped QuickStart operation.
15 *
16 * Unlike mode switching, this endpoint may create WordPress content and change
17 * setup options. It therefore uses a separate action, nonce, capability check,
18 * explicit browser confirmation, and live-demo mutation guard.
19 *
20 * @return void
21 */
22 function wpbc_booking_modes_ajax_quickstart() {
23
24 $mode_id = isset( $_POST['mode_id'] ) && is_scalar( $_POST['mode_id'] ) ? sanitize_key( wp_unslash( $_POST['mode_id'] ) ) : '';
25 $nonce = isset( $_POST['nonce'] ) && is_scalar( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
26 $validation = wpbc_booking_modes_validate_quickstart_request( $mode_id, $nonce );
27
28 if ( is_wp_error( $validation ) ) {
29 wp_send_json_error(
30 array(
31 'code' => $validation->get_error_code(),
32 'message' => $validation->get_error_message(),
33 ),
34 403
35 );
36 }
37
38 $lock_name = wpbc_booking_modes_acquire_quickstart_lock( $mode_id );
39
40 if ( is_wp_error( $lock_name ) ) {
41 wp_send_json_error(
42 array(
43 'code' => $lock_name->get_error_code(),
44 'message' => $lock_name->get_error_message(),
45 ),
46 409
47 );
48 }
49
50 try {
51 $result = wpbc_booking_modes_run_quickstart( $mode_id );
52 } finally {
53 wpbc_booking_modes_release_quickstart_lock( $lock_name );
54 }
55
56 if ( is_wp_error( $result ) ) {
57 wp_send_json_error(
58 array(
59 'code' => $result->get_error_code(),
60 'message' => $result->get_error_message(),
61 ),
62 400
63 );
64 }
65
66 wp_send_json_success( $result );
67 }
68 add_action( 'wp_ajax_WPBC_AJX_BOOKING_MODE_QUICKSTART', 'wpbc_booking_modes_ajax_quickstart' );
69