| 1 |
<?php |
| 2 |
/** |
| 3 |
* Easy Hotel - Native Checkout bootstrap. |
| 4 |
* |
| 5 |
* Pulls together the pricing, booking, email and gateway classes and |
| 6 |
* instantiates the public-facing checkout controller. Included from the |
| 7 |
* main plugin loader (see admin/includes/admin-init.php). |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
if ( ! defined( 'ESHB_NATIVE_CHECKOUT_PATH' ) ) { |
| 13 |
define( 'ESHB_NATIVE_CHECKOUT_PATH', plugin_dir_path( __FILE__ ) ); |
| 14 |
} |
| 15 |
if ( ! defined( 'ESHB_NATIVE_CHECKOUT_URL' ) ) { |
| 16 |
define( 'ESHB_NATIVE_CHECKOUT_URL', plugin_dir_url( __FILE__ ) ); |
| 17 |
} |
| 18 |
|
| 19 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'includes/helpers.php'; |
| 20 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'includes/class-coupon.php'; |
| 21 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'includes/class-pricing.php'; |
| 22 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'includes/class-booking-handler.php'; |
| 23 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'includes/class-email-handler.php'; |
| 24 |
|
| 25 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'gateways/abstract-gateway.php'; |
| 26 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'gateways/class-cod-gateway.php'; |
| 27 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'gateways/class-paypal-gateway.php'; |
| 28 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'gateways/class-gateway-manager.php'; |
| 29 |
|
| 30 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'includes/class-checkout.php'; |
| 31 |
|
| 32 |
// Customer account area + booking cancellation system. |
| 33 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'account/class-customer.php'; |
| 34 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'account/class-cancellation-email.php'; |
| 35 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'account/class-bookings.php'; |
| 36 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'account/class-account-ajax.php'; |
| 37 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'account/class-account-admin.php'; |
| 38 |
require_once ESHB_NATIVE_CHECKOUT_PATH . 'account/class-account.php'; |
| 39 |
|
| 40 |
add_action( 'plugins_loaded', function () { |
| 41 |
ESHB_Native_Checkout::instance(); |
| 42 |
ESHB_Native_Account::instance(); |
| 43 |
}, 15 ); |
| 44 |
|
| 45 |
/* ----------------------------------------------------------------------- |
| 46 |
* Abandoned-reservation cleanup |
| 47 |
* |
| 48 |
* Reservations live in wp_options keyed by the per-visitor token. A |
| 49 |
* customer who lands on the checkout page and then closes the tab or |
| 50 |
* cancels payment never triggers the on-success delete path, so we |
| 51 |
* need a janitor to keep wp_options from accumulating stale rows. |
| 52 |
* -------------------------------------------------------------------- */ |
| 53 |
|
| 54 |
add_action( 'eshb_native_checkout_cleanup_cron', 'eshb_native_checkout_cleanup_stale_reservations' ); |
| 55 |
|
| 56 |
add_action( 'init', function () { |
| 57 |
if ( ! wp_next_scheduled( 'eshb_native_checkout_cleanup_cron' ) ) { |
| 58 |
wp_schedule_event( time() + HOUR_IN_SECONDS, 'hourly', 'eshb_native_checkout_cleanup_cron' ); |
| 59 |
} |
| 60 |
} ); |
| 61 |
|
| 62 |
register_deactivation_hook( ESHB_PL_ROOT, 'eshb_native_checkout_unschedule_cleanup' ); |
| 63 |
if ( ! function_exists( 'eshb_native_checkout_unschedule_cleanup' ) ) { |
| 64 |
function eshb_native_checkout_unschedule_cleanup() { |
| 65 |
$timestamp = wp_next_scheduled( 'eshb_native_checkout_cleanup_cron' ); |
| 66 |
if ( $timestamp ) { |
| 67 |
wp_unschedule_event( $timestamp, 'eshb_native_checkout_cleanup_cron' ); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Auto-create the checkout page on plugin activation when Native Checkout |
| 74 |
* is in use, so the shortcode is always reachable from a known URL. |
| 75 |
*/ |
| 76 |
register_activation_hook( ESHB_PL_ROOT, 'eshb_native_checkout_create_page' ); |
| 77 |
if ( ! function_exists( 'eshb_native_checkout_create_page' ) ) { |
| 78 |
function eshb_native_checkout_create_page() { |
| 79 |
$existing = eshb_native_checkout_page_id(); |
| 80 |
if ( $existing ) return; |
| 81 |
|
| 82 |
$page_id = wp_insert_post( [ |
| 83 |
'post_title' => __( 'Easy Hotel Checkout', 'easy-hotel' ), |
| 84 |
'post_name' => 'eshb-checkout', |
| 85 |
'post_content' => '[eshb_native_checkout]', |
| 86 |
'post_status' => 'publish', |
| 87 |
'post_type' => 'page', |
| 88 |
] ); |
| 89 |
|
| 90 |
if ( ! is_wp_error( $page_id ) && $page_id ) { |
| 91 |
update_option( 'eshb_native_checkout_page_id', (int) $page_id ); |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Auto-create the customer account page on plugin activation so the |
| 98 |
* [eshb_account] shortcode is reachable from a known URL. |
| 99 |
*/ |
| 100 |
register_activation_hook( ESHB_PL_ROOT, 'eshb_native_account_create_page' ); |
| 101 |
if ( ! function_exists( 'eshb_native_account_create_page' ) ) { |
| 102 |
function eshb_native_account_create_page() { |
| 103 |
if ( class_exists( 'ESHB_Native_Account' ) ) { |
| 104 |
$account = ESHB_Native_Account::instance(); |
| 105 |
$account->customer->register_role(); |
| 106 |
$account->get_account_page_id( true ); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|