| 1 |
<?php |
| 2 |
/** |
| 3 |
* AJAX preview handler for Calendar settings. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* AJAX: refresh Calendar settings preview. |
| 14 |
* |
| 15 |
* @return void |
| 16 |
*/ |
| 17 |
function wpbc_settings_calendar_ajax_preview() { |
| 18 |
|
| 19 |
$nonce_result = check_ajax_referer( 'wpbc_settings_calendar_ajax_nonce', 'nonce', false ); |
| 20 |
if ( false === $nonce_result ) { |
| 21 |
wp_send_json_error( array( 'message' => __( 'Security check failed.', 'booking' ) ), 403 ); |
| 22 |
} |
| 23 |
|
| 24 |
if ( ! wpbc_is_mu_user_can_be_here( 'only_super_admin' ) || ! current_user_can( wpbc_settings_calendar__get_manage_cap() ) ) { |
| 25 |
wp_send_json_error( array( 'message' => __( 'You do not have permission to preview calendar settings.', 'booking' ) ), 403 ); |
| 26 |
} |
| 27 |
|
| 28 |
$resource_id = isset( $_POST['resource_id'] ) ? absint( wp_unslash( $_POST['resource_id'] ) ) : wpbc_settings_calendar__get_preview_resource_id(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 29 |
$months_count = isset( $_POST['months_count'] ) ? absint( wp_unslash( $_POST['months_count'] ) ) : wpbc_settings_calendar__get_preview_months_count(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 30 |
$resource_id = wpbc_settings_calendar__sanitize_preview_resource_id( $resource_id ); |
| 31 |
$months_count = wpbc_settings_calendar__sanitize_preview_months_count( $months_count ); |
| 32 |
$preview_settings = wpbc_settings_calendar__validate_data( $_POST, true ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing |
| 33 |
|
| 34 |
ob_start(); |
| 35 |
wpbc_settings_calendar__render_calendar_preview( $resource_id, $months_count, $preview_settings ); |
| 36 |
$html = ob_get_clean(); |
| 37 |
|
| 38 |
wp_send_json_success( |
| 39 |
array( |
| 40 |
'html' => $html, |
| 41 |
'resource_id' => $resource_id, |
| 42 |
'months_count' => $months_count, |
| 43 |
'days_selection' => wpbc_settings_calendar__get_days_selection_response( $preview_settings ), |
| 44 |
) |
| 45 |
); |
| 46 |
} |
| 47 |
add_action( 'wp_ajax_WPBC_AJX_SETTINGS_CALENDAR_PREVIEW', 'wpbc_settings_calendar_ajax_preview' ); |
| 48 |
|