PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 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 All 205 releases
← All changes | includes/booking-appointment/ajax/booking-appointment__validate-time.php +15 -7 11.5 → 11.9 View file →
@@ -93,12 +93,13 @@
93 93 * @param string[] $dates Selected SQL dates.
94 94 * @param string $start_time Strict browser time value.
95 95 * @param int $maximum_duration Maximum allowed duration in minutes.
96 96 * @param array<int,array<string,int>> $existing_intervals Existing Provider intervals.
97 + * @param int $provider_id Provider resource ID.
97 98 *
98 99 * @return array<string,mixed> Public, non-sensitive validation result.
99 100 */
100 -function wpbc_booking_appointment_validate_one_start_time( $service, $dates, $start_time, $maximum_duration, $existing_intervals ) {
101 +function wpbc_booking_appointment_validate_one_start_time( $service, $dates, $start_time, $maximum_duration, $existing_intervals, $provider_id = 0 ) {
101 102 $start_seconds = wpbc_booking_appointment_get_preflight_start_seconds( $start_time );
102 103 if ( is_wp_error( $start_seconds ) ) {
103 104 return array( 'valid' => false, 'message' => $start_seconds->get_error_message(), 'code' => $start_seconds->get_error_code() );
104 105 }
@@ -107,8 +108,19 @@
107 108 if ( is_wp_error( $end_seconds ) ) {
108 109 return array( 'valid' => false, 'message' => $end_seconds->get_error_message(), 'code' => $end_seconds->get_error_code() );
109 110 }
110 111
112 + $working_time_check = wpbc_appointment_services_check_working_time( $service, $provider_id, $dates, array( $start_seconds, $end_seconds ) );
113 + if ( is_wp_error( $working_time_check ) ) {
114 + return array(
115 + 'valid' => false,
116 + 'message' => $working_time_check->get_error_message(),
117 + 'code' => $working_time_check->get_error_code(),
118 + 'start_time' => sanitize_text_field( $start_time ),
119 + 'end_time' => wpbc_transform__seconds__in__24_hours_his( $end_seconds ),
120 + );
121 + }
122 +
111 123 $buffer_check = wpbc_appointment_services_check_buffer_conflicts_in_intervals( $service, $dates, array( $start_seconds, $end_seconds ), $existing_intervals );
112 124 if ( is_wp_error( $buffer_check ) ) {
113 125 return array(
114 126 'valid' => false,
@@ -136,12 +148,8 @@
136 148 *
137 149 * @return void Terminates with a JSON response.
138 150 */
139 151 function wpbc_booking_appointment_ajax_validate_time() {
140 - if ( ! function_exists( 'wpbc_is_11_5_features_enabled' ) || ! wpbc_is_11_5_features_enabled() ) {
141 - wp_send_json_error( array( 'message' => __( 'Appointment booking is not enabled.', 'booking' ) ), 404 );
142 - }
143 -
144 152 if ( false === check_ajax_referer( 'wpbc_booking_appointment_ajax', 'nonce', false ) ) {
145 153 wp_send_json_error( array( 'message' => __( 'Security check failed. Reload the page and try again.', 'booking' ) ), 403 );
146 154 }
147 155
@@ -174,9 +182,9 @@
174 182 }
175 183
176 184 $slots = array();
177 185 foreach ( $start_times as $start_time ) {
178 - $slots[ $start_time ] = wpbc_booking_appointment_validate_one_start_time( $service, $dates, $start_time, $maximum_duration, $existing_intervals );
186 + $slots[ $start_time ] = wpbc_booking_appointment_validate_one_start_time( $service, $dates, $start_time, $maximum_duration, $existing_intervals, $provider_id );
179 187 }
180 188 wp_send_json_success(
181 189 array(
182 190 'valid' => true,
@@ -188,9 +196,9 @@
188 196 );
189 197 }
190 198
191 199 $start_time = isset( $_POST['start_time'] ) && ! is_array( $_POST['start_time'] ) ? sanitize_text_field( wp_unslash( $_POST['start_time'] ) ) : '';
192 - $result = wpbc_booking_appointment_validate_one_start_time( $service, $dates, $start_time, $maximum_duration, $existing_intervals );
200 + $result = wpbc_booking_appointment_validate_one_start_time( $service, $dates, $start_time, $maximum_duration, $existing_intervals, $provider_id );
193 201 if ( empty( $result['valid'] ) ) {
194 202 wp_send_json_success( $result );
195 203 }
196 204