| 1 |
<?php |
| 2 |
/** |
| 3 |
* WooCommerce compatibility helpers. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @subpackage Compatibility |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Allow intentionally public Booking Calendar AJAX actions through WooCommerce's admin-access guard. |
| 15 |
* |
| 16 |
* WooCommerce normally excludes admin-ajax.php from its customer admin redirect. Some server configurations report |
| 17 |
* a different SCRIPT_FILENAME, which can make WooCommerce redirect a valid public AJAX request to the My Account page. |
| 18 |
* This compatibility layer changes that decision only for Booking Calendar actions that are explicitly registered |
| 19 |
* for logged-out visitors. It does not alter access to any WordPress administration screen or protected AJAX action. |
| 20 |
* |
| 21 |
* @param bool $prevent_access Whether WooCommerce should prevent access to the current administration request. |
| 22 |
* @return bool False for a registered public Booking Calendar AJAX action; otherwise the original decision. |
| 23 |
*/ |
| 24 |
function wpbc_woocommerce_allow_public_ajax_access( $prevent_access ) { |
| 25 |
if ( ! $prevent_access || ! wp_doing_ajax() ) { |
| 26 |
return $prevent_access; |
| 27 |
} |
| 28 |
|
| 29 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- The destination AJAX callback verifies its own request. |
| 30 |
if ( ! isset( $_POST['action'] ) || ! is_string( $_POST['action'] ) ) { |
| 31 |
return $prevent_access; |
| 32 |
} |
| 33 |
|
| 34 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Used only to identify the destination AJAX callback. |
| 35 |
$ajax_action = sanitize_text_field( wp_unslash( $_POST['action'] ) ); |
| 36 |
|
| 37 |
$public_ajax_actions = array( |
| 38 |
'WPBC_AJX_CALENDAR_LOAD', |
| 39 |
'WPBC_AJX_BOOKING__CREATE', |
| 40 |
'WPBC_AJX_BOOKING_APPOINTMENT_RESOLVE', |
| 41 |
'WPBC_AJX_BOOKING_APPOINTMENT_VALIDATE_TIME', |
| 42 |
'WPBC_AJX_BOOKING_RESOURCE_SELECTOR_RESOLVE', |
| 43 |
'WPBC_AJX_AVAILABILITY_TIMESLOTS_READ', |
| 44 |
'WPBC_FLEXTIMELINE_NAV', |
| 45 |
'CALCULATE_THE_COST', |
| 46 |
'DELETE_BY_VISITOR', |
| 47 |
'BOOKING_SEARCH', |
| 48 |
'WPBC_PAY_VIA_iDEAL', |
| 49 |
); |
| 50 |
|
| 51 |
if ( ! in_array( $ajax_action, $public_ajax_actions, true ) ) { |
| 52 |
return $prevent_access; |
| 53 |
} |
| 54 |
|
| 55 |
if ( false === has_action( 'wp_ajax_nopriv_' . $ajax_action ) ) { |
| 56 |
return $prevent_access; |
| 57 |
} |
| 58 |
|
| 59 |
return false; |
| 60 |
} |
| 61 |
add_filter( 'woocommerce_prevent_admin_access', 'wpbc_woocommerce_allow_public_ajax_access', PHP_INT_MAX ); |
| 62 |
|