| 1 |
<?php |
| 2 |
/** |
| 3 |
* AJAX preview handler for Appearance / Theme. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* AJAX: refresh Appearance / Theme calendar preview. |
| 14 |
* |
| 15 |
* @return void |
| 16 |
*/ |
| 17 |
function wpbc_settings_themes_ajax_preview() { |
| 18 |
|
| 19 |
$nonce_result = check_ajax_referer( 'wpbc_settings_themes_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_themes__get_manage_cap() ) ) { |
| 25 |
wp_send_json_error( array( 'message' => __( 'You do not have permission to preview appearance settings.', 'booking' ) ), 403 ); |
| 26 |
} |
| 27 |
|
| 28 |
$resource_id = isset( $_POST['resource_id'] ) ? absint( wp_unslash( $_POST['resource_id'] ) ) : wpbc_settings_themes__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_themes__get_preview_months_count(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 30 |
$preview_mode = isset( $_POST['preview_mode'] ) ? sanitize_key( wp_unslash( $_POST['preview_mode'] ) ) : wpbc_settings_themes__get_preview_mode(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 31 |
$custom_booking_form = isset( $_POST['custom_booking_form'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_booking_form'] ) ) : wpbc_settings_themes__get_custom_booking_form(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 32 |
|
| 33 |
$resource_id = wpbc_settings_themes__sanitize_preview_resource_id( $resource_id ); |
| 34 |
$months_count = wpbc_settings_themes__sanitize_preview_months_count( $months_count ); |
| 35 |
$preview_mode = wpbc_settings_themes__sanitize_preview_mode( $preview_mode ); |
| 36 |
$custom_booking_form = wpbc_settings_themes__sanitize_custom_booking_form( $custom_booking_form ); |
| 37 |
$preview_settings = wpbc_settings_themes__validate_data( $_POST ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing |
| 38 |
|
| 39 |
ob_start(); |
| 40 |
wpbc_settings_themes__render_calendar_preview( $resource_id, $months_count, $preview_settings, $preview_mode, $custom_booking_form ); |
| 41 |
$html = ob_get_clean(); |
| 42 |
|
| 43 |
wp_send_json_success( |
| 44 |
array( |
| 45 |
'html' => $html, |
| 46 |
'resource_id' => $resource_id, |
| 47 |
'months_count' => $months_count, |
| 48 |
'preview_mode' => $preview_mode, |
| 49 |
'custom_booking_form' => $custom_booking_form, |
| 50 |
'days_selection' => wpbc_settings_themes__get_days_selection_response(), |
| 51 |
) |
| 52 |
); |
| 53 |
} |
| 54 |
add_action( 'wp_ajax_WPBC_AJX_SETTINGS_THEMES_PREVIEW', 'wpbc_settings_themes_ajax_preview' ); |
| 55 |
|