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 / quickstart / rental.php

rental.php in Booking Calendar 11.8.4, at includes/booking_modes_v3/quickstart/rental.php

120 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Rental mode QuickStart operation.
4 *
5 * @package Booking Calendar
6 * @since 11.5.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Apply the minimum Rental date-range and changeover configuration once.
15 *
16 * The caller persists a profile marker immediately after this function. Later
17 * retries therefore preserve any manual changes made after initial QuickStart.
18 * Booking Form layout, themes, email, pricing, and existing resources are not
19 * overwritten.
20 *
21 * @return void
22 */
23 function wpbc_booking_modes_quickstart_apply_rental_profile() {
24
25 update_bk_option( 'booking_type_of_day_selections', 'range' );
26 update_bk_option( 'booking_range_selection_type', 'dynamic' );
27 update_bk_option( 'booking_range_selection_days_count', '2' );
28 update_bk_option( 'booking_range_selection_days_max_count_dynamic', 30 );
29 update_bk_option( 'booking_range_selection_days_specific_num_dynamic', '' );
30 update_bk_option( 'booking_range_start_day', '-1' );
31 update_bk_option( 'booking_range_selection_days_count_dynamic', '2' );
32 update_bk_option( 'booking_range_start_day_dynamic', '-1' );
33 update_bk_option( 'booking_range_selection_time_is_active', 'On' );
34 update_bk_option( 'booking_range_selection_start_time', '14:00' );
35 update_bk_option( 'booking_range_selection_end_time', '12:00' );
36 update_bk_option( 'booking_change_over_days_triangles', 'On' );
37 update_bk_option( 'booking_recurrent_time', 'Off' );
38 }
39
40 /**
41 * Run Rental QuickStart using the active edition's supported engines.
42 *
43 * The first existing Booking Resource is reused as the Property. The rental
44 * date-range profile is applied only once, a public Property page is ensured,
45 * and Business Large receives a separate availability-search page. Capacity,
46 * pricing, and extras remain guided follow-up operations because QuickStart
47 * must not invent commercial values for existing customer resources.
48 *
49 * @return array<string,mixed>|WP_Error QuickStart result, or an error.
50 */
51 function wpbc_booking_modes_run_rental_quickstart() {
52
53 $state = wpbc_booking_modes_get_quickstart_state( 'rental' );
54 $resource_id = wpbc_booking_modes_quickstart_get_first_resource_id();
55
56 if ( is_wp_error( $resource_id ) ) {
57 return $resource_id;
58 }
59
60 if ( empty( $state['profile_version'] ) ) {
61 wpbc_booking_modes_quickstart_apply_rental_profile();
62 $state['profile_version'] = 1;
63 $profile_state_result = wpbc_booking_modes_set_quickstart_state( 'rental', $state );
64
65 if ( is_wp_error( $profile_state_result ) ) {
66 return $profile_state_result;
67 }
68 }
69
70 $property_page = wpbc_booking_modes_quickstart_ensure_page(
71 'rental_property_booking',
72 'wpbc-rental-booking',
73 __( 'Book a Property', 'booking' ),
74 '[booking resource_id=' . absint( $resource_id ) . ']',
75 '[booking resource_id=' . absint( $resource_id )
76 );
77
78 if ( is_wp_error( $property_page ) ) {
79 return $property_page;
80 }
81
82 $search_page = array();
83 if ( class_exists( 'wpdev_bk_biz_l' ) && shortcode_exists( 'bookingsearch' ) ) {
84 $search_page = wpbc_booking_modes_quickstart_ensure_page(
85 'rental_availability_search',
86 'wpbc-rental-search',
87 __( 'Search Property Availability', 'booking' ),
88 '[bookingsearch]',
89 '[bookingsearch'
90 );
91
92 if ( is_wp_error( $search_page ) ) {
93 return $search_page;
94 }
95 }
96
97 $state['completed'] = true;
98 $state['completed_at'] = ! empty( $state['completed_at'] ) ? $state['completed_at'] : current_time( 'mysql' );
99 $state['resource_id'] = absint( $resource_id );
100 $state['page_id'] = absint( $property_page['page_id'] );
101 $state['search_page_id'] = ! empty( $search_page['page_id'] ) ? absint( $search_page['page_id'] ) : 0;
102 $state_result = wpbc_booking_modes_set_quickstart_state( 'rental', $state );
103
104 if ( is_wp_error( $state_result ) ) {
105 return $state_result;
106 }
107
108 return array(
109 'mode_id' => 'rental',
110 'message' => __( 'Rental QuickStart is ready. Review capacity, pricing, extras, and availability, then test the booking page.', 'booking' ),
111 'test_url' => $property_page['test_url'],
112 'page_id' => absint( $property_page['page_id'] ),
113 'resource_id' => absint( $resource_id ),
114 'search_url' => ! empty( $search_page['test_url'] ) ? $search_page['test_url'] : '',
115 'capacity_url' => wpbc_booking_modes_get_canonical_page_url( 'wpbc-resources__capacity' ),
116 'pricing_url' => wpbc_booking_modes_get_canonical_page_url( 'wpbc-prices__cost' ),
117 'availability_url' => wpbc_booking_modes_get_canonical_page_url( 'wpbc-availability__availability' ),
118 );
119 }
120