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/page-availability-general/availability_general__page.php +308 -116 11.8.3 → 11.9 View file →
@@ -105,13 +105,17 @@
105 105 'loading' => __( 'Loading', 'booking' ),
106 106 'buffer_preview' => __( 'Buffer preview', 'booking' ),
107 107 'before_booking' => __( 'Before booking', 'booking' ),
108 108 'after_booking' => __( 'After booking', 'booking' ),
109 - 'no_buffer' => __( 'No booking buffer is selected.', 'booking' ),
110 - ),
111 - )
112 - );
113 -}
109 + 'no_buffer' => __( 'No booking buffer is selected.', 'booking' ),
110 + 'add_interval' => __( 'Add interval', 'booking' ),
111 + 'remove_interval' => __( 'Remove working interval', 'booking' ),
112 + 'interval_limit' => __( 'No additional one-hour interval is available for this weekday.', 'booking' ),
113 + ),
114 + 'max_working_time_intervals' => wpbc_availability_general__get_max_working_time_intervals_per_day(),
115 + )
116 + );
117 +}
114 118 add_action( 'wpbc_enqueue_js_files', 'wpbc_availability_general_enqueue_js_files', 66 );
115 119
116 120 /**
117 121 * Print tooltip initializer for General Availability.
@@ -336,13 +340,13 @@
336 340
337 341 /**
338 342 * Get time options for future working-time controls.
339 343 *
340 - * @param string $selected Selected value.
344 + * @param string|string[] $selected Selected values that must remain available.
341 345 *
342 346 * @return array
343 347 */
344 -function wpbc_availability_general__get_working_time_options( $selected = '' ) {
348 +function wpbc_availability_general__get_working_time_options( $selected = '' ) {
345 349
346 350 $options = array();
347 351
348 352 for ( $minutes = 0; $minutes <= 1440; $minutes += 30 ) {
@@ -353,15 +357,79 @@
353 357
354 358 $options[ $value ] = $label;
355 359 }
356 360
357 - if ( '' !== $selected && ! isset( $options[ $selected ] ) ) {
358 - $options[ $selected ] = $selected;
359 - }
361 + $selected_values = is_array( $selected ) ? $selected : array( $selected );
362 + foreach ( $selected_values as $selected_value ) {
363 + $selected_value = is_scalar( $selected_value ) ? (string) $selected_value : '';
364 + if ( '' !== $selected_value && ! isset( $options[ $selected_value ] ) ) {
365 + $options[ $selected_value ] = $selected_value;
366 + }
367 + }
368 +
369 + uksort(
370 + $options,
371 + function ( $first_time, $second_time ) {
372 + return wpbc_working_time__time_to_seconds( $first_time ) - wpbc_working_time__time_to_seconds( $second_time );
373 + }
374 + );
375 +
376 + return $options;
377 +}
378 +
379 +/**
380 + * Return the maximum number of editable intervals for one weekday.
381 + *
382 + * @return int Maximum interval count.
383 + */
384 +function wpbc_availability_general__get_max_working_time_intervals_per_day() {
385 +
386 + return 8;
387 +}
388 +
389 +/**
390 + * Collect every stored endpoint needed by the current inspector selects.
391 + *
392 + * Resource switching happens without reloading the inspector. Including all
393 + * canonical endpoints prevents a minute-aligned custom time from disappearing
394 + * when the selected resource changes in the browser.
395 + *
396 + * @param array $working_time_settings Canonical Working Time settings.
397 + *
398 + * @return string[] Unique H:i endpoints.
399 + */
400 +function wpbc_availability_general__get_working_time_option_values( $working_time_settings ) {
401 +
402 + $selected_values = array();
403 + $schedules = array();
404 +
405 + if ( isset( $working_time_settings['default']['weekdays'] ) ) {
406 + $schedules[] = $working_time_settings['default']['weekdays'];
407 + }
408 + if ( isset( $working_time_settings['resources'] ) && is_array( $working_time_settings['resources'] ) ) {
409 + foreach ( $working_time_settings['resources'] as $resource_settings ) {
410 + if ( isset( $resource_settings['weekdays'] ) ) {
411 + $schedules[] = $resource_settings['weekdays'];
412 + }
413 + }
414 + }
415 +
416 + foreach ( $schedules as $weekdays ) {
417 + foreach ( (array) $weekdays as $day_intervals ) {
418 + foreach ( (array) $day_intervals as $interval ) {
419 + if ( isset( $interval['start_second'] ) ) {
420 + $selected_values[] = wpbc_working_time__seconds_to_time( $interval['start_second'] );
421 + }
422 + if ( isset( $interval['end_second'] ) ) {
423 + $selected_values[] = wpbc_working_time__seconds_to_time( $interval['end_second'] );
424 + }
425 + }
426 + }
427 + }
428 +
429 + return array_values( array_unique( $selected_values ) );
430 +}
360 431
361 - return $options;
362 -}
363 -
364 432 /**
365 433 * Render a select field.
366 434 *
367 435 * @param string $name Field name.
@@ -392,14 +460,15 @@
392 460
393 461 /**
394 462 * Render Working Time weekday rows.
395 463 *
396 - * @param string $prefix Field prefix.
397 - * @param array $weekdays Weekday intervals.
464 + * @param string $prefix Field prefix.
465 + * @param array $weekdays Weekday intervals.
466 + * @param array $time_options Allowed time choices.
398 467 *
399 468 * @return void
400 469 */
401 -function wpbc_availability_general__render_working_time_weekdays( $prefix, $weekdays ) {
470 +function wpbc_availability_general__render_working_time_weekdays( $prefix, $weekdays, $time_options = array() ) {
402 471
403 472 $days = array(
404 473 0 => _x( 'Sun', 'Short weekday name', 'booking' ),
405 474 1 => _x( 'Mon', 'Short weekday name', 'booking' ),
@@ -414,49 +483,103 @@
414 483 if ( $start_week_day > 6 ) {
415 484 $start_week_day = 0;
416 485 }
417 486 $days_ordered = array_slice( $days, $start_week_day, null, true ) + array_slice( $days, 0, $start_week_day, true );
418 - $time_options = wpbc_availability_general__get_working_time_options();
419 - ?>
420 - <div class="wpbc_ag_working_time_rows" data-wpbc-working-time-weekdays="<?php echo esc_attr( $prefix ); ?>">
421 - <?php foreach ( $days_ordered as $day_num => $day_title ) : ?>
422 - <?php
423 - $interval = ! empty( $weekdays[ $day_num ][0] ) ? $weekdays[ $day_num ][0] : array( 'start_second' => 9 * HOUR_IN_SECONDS, 'end_second' => 18 * HOUR_IN_SECONDS );
424 - $is_open = ! empty( $weekdays[ $day_num ] );
425 - ?>
426 - <div class="wpbc_ag_working_time_row">
427 - <label class="wpbc_ag_switch wpbc_ag_working_time_day">
428 - <input type="checkbox" name="<?php echo esc_attr( $prefix ); ?>_days[]" value="<?php echo esc_attr( $day_num ); ?>" <?php checked( $is_open ); ?> />
429 - <span class="wpbc_ag_switch_control" aria-hidden="true"><span class="wpbc_ag_switch_knob"></span></span>
430 - <span class="wpbc_ag_switch_label"><?php echo esc_html( $day_title ); ?></span>
431 - </label>
432 - <div class="wpbc_ag_working_time_times">
433 - <?php
434 - wpbc_availability_general__render_select(
435 - $prefix . '_start[' . $day_num . ']',
436 - $time_options,
437 - wpbc_working_time__seconds_to_time( $interval['start_second'] ),
438 - array(
439 - 'id' => $prefix . '_start_' . $day_num,
440 - 'class' => 'wpbc_ag_field_control wpbc_ag_working_time_start',
441 - )
442 - );
443 - wpbc_availability_general__render_select(
444 - $prefix . '_end[' . $day_num . ']',
445 - $time_options,
446 - wpbc_working_time__seconds_to_time( $interval['end_second'] ),
447 - array(
448 - 'id' => $prefix . '_end_' . $day_num,
449 - 'class' => 'wpbc_ag_field_control wpbc_ag_working_time_end',
450 - )
451 - );
452 - ?>
453 - </div>
454 - </div>
455 - <?php endforeach; ?>
456 - </div>
457 - <?php
458 -}
487 + if ( empty( $time_options ) ) {
488 + $time_options = wpbc_availability_general__get_working_time_options();
489 + }
490 + ?>
491 + <div
492 + class="wpbc_ag_working_time_rows"
493 + data-wpbc-working-time-weekdays="<?php echo esc_attr( $prefix ); ?>"
494 + data-max-intervals="<?php echo esc_attr( (string) wpbc_availability_general__get_max_working_time_intervals_per_day() ); ?>"
495 + >
496 + <?php foreach ( $days_ordered as $day_num => $day_title ) : ?>
497 + <?php
498 + $day_intervals = ! empty( $weekdays[ $day_num ] ) && is_array( $weekdays[ $day_num ] )
499 + ? array_values( $weekdays[ $day_num ] )
500 + : array();
501 + $is_open = ! empty( $day_intervals );
502 + $display_intervals = $is_open
503 + ? $day_intervals
504 + : array( array( 'start_second' => 9 * HOUR_IN_SECONDS, 'end_second' => 18 * HOUR_IN_SECONDS ) );
505 + /* translators: %s: Short weekday name. */
506 + $intervals_label = sprintf( __( '%s Working Time intervals', 'booking' ), $day_title );
507 + /* translators: %s: Short weekday name. */
508 + $add_interval_label = sprintf( __( 'Add %s Working Time interval', 'booking' ), $day_title );
509 + ?>
510 + <div class="wpbc_ag_working_time_row<?php echo $is_open ? ' is-enabled' : ''; ?>" data-wpbc-working-time-day="<?php echo esc_attr( (string) $day_num ); ?>">
511 + <label class="wpbc_ag_switch wpbc_ag_working_time_day">
512 + <input type="checkbox" name="<?php echo esc_attr( $prefix ); ?>_days[]" value="<?php echo esc_attr( $day_num ); ?>" data-wpbc-working-time-day-toggle="1" <?php checked( $is_open ); ?> />
513 + <span class="wpbc_ag_switch_control" aria-hidden="true"><span class="wpbc_ag_switch_knob"></span></span>
514 + <span class="wpbc_ag_switch_label"><?php echo esc_html( $day_title ); ?></span>
515 + </label>
516 + <div class="wpbc_ag_working_time_intervals" data-wpbc-working-time-intervals="1" aria-label="<?php echo esc_attr( $intervals_label ); ?>">
517 + <?php foreach ( $display_intervals as $interval_index => $interval ) : ?>
518 + <?php wpbc_availability_general__render_working_time_interval( $prefix, $day_num, $day_title, $interval_index, $interval, $time_options ); ?>
519 + <?php endforeach; ?>
520 + </div>
521 + <button type="button" class="button-link wpbc_ag_working_time_add" data-wpbc-add-working-time-interval="1" aria-label="<?php echo esc_attr( $add_interval_label ); ?>">
522 + <i class="menu_icon icon-1x wpbc_icn_add" aria-hidden="true"></i>
523 + <span><?php esc_html_e( 'Add interval', 'booking' ); ?></span>
524 + </button>
525 + </div>
526 + <?php endforeach; ?>
527 + </div>
528 + <?php
529 +}
530 +
531 +/**
532 + * Render one editable Working Time interval.
533 + *
534 + * @param string $prefix Field prefix.
535 + * @param int $day_num Canonical weekday number from 0 through 6.
536 + * @param string $day_title Localized weekday title.
537 + * @param int $interval_index Zero-based interval index.
538 + * @param array $interval Canonical interval values.
539 + * @param array $time_options Allowed time choices.
540 + *
541 + * @return void
542 + */
543 +function wpbc_availability_general__render_working_time_interval( $prefix, $day_num, $day_title, $interval_index, $interval, $time_options ) {
544 +
545 + $start_id = $prefix . '_start_' . $day_num . '_' . $interval_index;
546 + $end_id = $prefix . '_end_' . $day_num . '_' . $interval_index;
547 + /* translators: %s: Short weekday name. */
548 + $remove_label = sprintf( __( 'Remove %s Working Time interval', 'booking' ), $day_title );
549 + ?>
550 + <div class="wpbc_ag_working_time_times" data-wpbc-working-time-interval="1" data-interval-index="<?php echo esc_attr( (string) $interval_index ); ?>">
551 + <label class="screen-reader-text" for="<?php echo esc_attr( $start_id ); ?>"><?php esc_html_e( 'Start time', 'booking' ); ?></label>
552 + <?php
553 + wpbc_availability_general__render_select(
554 + $prefix . '_start[' . $day_num . '][]',
555 + $time_options,
556 + wpbc_working_time__seconds_to_time( $interval['start_second'] ),
557 + array(
558 + 'id' => $start_id,
559 + 'class' => 'wpbc_ag_field_control wpbc_ag_working_time_start',
560 + )
561 + );
562 + ?>
563 + <span class="wpbc_ag_working_time_separator" aria-hidden="true">&ndash;</span>
564 + <label class="screen-reader-text" for="<?php echo esc_attr( $end_id ); ?>"><?php esc_html_e( 'End time', 'booking' ); ?></label>
565 + <?php
566 + wpbc_availability_general__render_select(
567 + $prefix . '_end[' . $day_num . '][]',
568 + $time_options,
569 + wpbc_working_time__seconds_to_time( $interval['end_second'] ),
570 + array(
571 + 'id' => $end_id,
572 + 'class' => 'wpbc_ag_field_control wpbc_ag_working_time_end',
573 + )
574 + );
575 + ?>
576 + <button type="button" class="wpbc_ag_working_time_remove" data-wpbc-remove-working-time-interval="1" aria-label="<?php echo esc_attr( $remove_label ); ?>">
577 + <i class="menu_icon icon-1x wpbc_icn_delete_outline" aria-hidden="true"></i>
578 + </button>
579 + </div>
580 + <?php
581 +}
459 582
460 583 /**
461 584 * Get default General Availability settings.
462 585 *
@@ -477,16 +600,37 @@
477 600 );
478 601 }
479 602
480 603 /**
481 - * Validate posted one-interval-per-weekday Working Time schedule.
482 - *
483 - * @param array $post_data Raw post data.
484 - * @param string $prefix Field prefix.
485 - *
486 - * @return array
487 - */
488 -function wpbc_availability_general__validate_working_time_weekdays( $post_data, $prefix ) {
604 + * Convert one posted Working Time value to canonical seconds.
605 + *
606 + * @param mixed $raw_time Untrusted H:i value.
607 + *
608 + * @return int|null Seconds from midnight, or null when invalid.
609 + */
610 +function wpbc_availability_general__validate_working_time_value( $raw_time ) {
611 +
612 + if ( ! is_scalar( $raw_time ) ) {
613 + return null;
614 + }
615 +
616 + $time_value = sanitize_text_field( (string) $raw_time );
617 + if ( ! preg_match( '/^(?:(?:[01]\d|2[0-3]):[0-5]\d|24:00)$/', $time_value ) ) {
618 + return null;
619 + }
620 +
621 + return wpbc_working_time__time_to_seconds( $time_value );
622 +}
623 +
624 +/**
625 + * Validate posted multi-interval Working Time weekdays.
626 + *
627 + * @param array $post_data Raw post data.
628 + * @param string $prefix Field prefix.
629 + *
630 + * @return array<int,array<int,array{start_second:int,end_second:int}>>|WP_Error Validated schedule or an error.
631 + */
632 +function wpbc_availability_general__validate_working_time_weekdays( $post_data, $prefix ) {
489 633
490 634 $weekdays = array();
491 635 $enabled_days = array();
492 636 $start_values = isset( $post_data[ $prefix . '_start' ] ) && is_array( $post_data[ $prefix . '_start' ] ) ? wp_unslash( $post_data[ $prefix . '_start' ] ) : array();
@@ -492,44 +636,54 @@
492 636 $start_values = isset( $post_data[ $prefix . '_start' ] ) && is_array( $post_data[ $prefix . '_start' ] ) ? wp_unslash( $post_data[ $prefix . '_start' ] ) : array();
493 637 $end_values = isset( $post_data[ $prefix . '_end' ] ) && is_array( $post_data[ $prefix . '_end' ] ) ? wp_unslash( $post_data[ $prefix . '_end' ] ) : array();
494 638
495 639 if ( isset( $post_data[ $prefix . '_days' ] ) && is_array( $post_data[ $prefix . '_days' ] ) ) {
496 - foreach ( $post_data[ $prefix . '_days' ] as $day_num ) {
497 - $day_num = absint( $day_num );
498 - if ( $day_num >= 0 && $day_num <= 6 ) {
499 - $enabled_days[] = $day_num;
500 - }
501 - }
502 - }
640 + foreach ( wp_unslash( $post_data[ $prefix . '_days' ] ) as $day_num ) {
641 + if ( is_scalar( $day_num ) && preg_match( '/^[0-6]$/', (string) $day_num ) ) {
642 + $enabled_days[] = (int) $day_num;
643 + }
644 + }
645 + }
646 + $enabled_days = array_values( array_unique( $enabled_days ) );
647 +
648 + for ( $day = 0; $day <= 6; $day++ ) {
649 + $weekdays[ $day ] = array();
650 + if ( ! in_array( $day, $enabled_days, true ) ) {
651 + continue;
652 + }
653 +
654 + $day_start_values = isset( $start_values[ $day ] ) ? array_values( (array) $start_values[ $day ] ) : array();
655 + $day_end_values = isset( $end_values[ $day ] ) ? array_values( (array) $end_values[ $day ] ) : array();
656 + if ( empty( $day_start_values ) || count( $day_start_values ) !== count( $day_end_values ) ) {
657 + return new WP_Error( 'wpbc_availability_general_working_time_interval_missing', __( 'Every enabled weekday must contain a complete Working Time interval.', 'booking' ) );
658 + }
659 +
660 + foreach ( $day_start_values as $interval_index => $raw_start_value ) {
661 + $start_second = wpbc_availability_general__validate_working_time_value( $raw_start_value );
662 + $end_second = wpbc_availability_general__validate_working_time_value( $day_end_values[ $interval_index ] );
663 +
664 + if ( null === $start_second || null === $end_second ) {
665 + return new WP_Error( 'wpbc_availability_general_working_time_value_invalid', __( 'Enter a valid start and end time for every Working Time interval.', 'booking' ) );
666 + }
667 +
668 + $weekdays[ $day ][] = array(
669 + 'start_second' => $start_second,
670 + 'end_second' => $end_second,
671 + );
672 + }
673 + }
674 +
675 + return wpbc_working_time__validate_weekday_intervals( $weekdays, wpbc_availability_general__get_max_working_time_intervals_per_day() );
676 +}
503 677
504 - for ( $day = 0; $day <= 6; $day++ ) {
505 - $weekdays[ $day ] = array();
506 - if ( ! in_array( $day, $enabled_days, true ) ) {
507 - continue;
508 - }
509 -
510 - $start = isset( $start_values[ $day ] ) ? wpbc_working_time__time_to_seconds( sanitize_text_field( $start_values[ $day ] ) ) : 0;
511 - $end = isset( $end_values[ $day ] ) ? wpbc_working_time__time_to_seconds( sanitize_text_field( $end_values[ $day ] ) ) : 0;
512 -
513 - if ( $start < $end ) {
514 - $weekdays[ $day ][] = array(
515 - 'start_second' => $start,
516 - 'end_second' => $end,
517 - );
518 - }
519 - }
520 -
521 - return $weekdays;
522 -}
523 -
524 678 /**
525 679 * Validate posted Working Time settings.
526 680 *
527 681 * @param array $post_data Raw post data.
528 682 *
529 - * @return array
530 - */
531 -function wpbc_availability_general__validate_working_time_data( $post_data ) {
683 + * @return array|WP_Error Validated Working Time settings or an error.
684 + */
685 +function wpbc_availability_general__validate_working_time_data( $post_data ) {
532 686
533 687 $current_settings = wpbc_working_time__get_settings();
534 688 $resource_id = isset( $post_data['booking_working_time_resource_id'] ) ? absint( wp_unslash( $post_data['booking_working_time_resource_id'] ) ) : 0;
535 689 $resource_mode = isset( $post_data['booking_working_time_resource_mode'] ) ? sanitize_key( wp_unslash( $post_data['booking_working_time_resource_mode'] ) ) : 'inherit';
@@ -537,18 +691,33 @@
537 691 if ( ! in_array( $resource_mode, array( 'inherit', 'custom', 'disabled' ), true ) ) {
538 692 $resource_mode = 'inherit';
539 693 }
540 694
541 - $current_settings['enabled'] = ( isset( $post_data['booking_working_time_enabled'] ) && 'On' === sanitize_text_field( wp_unslash( $post_data['booking_working_time_enabled'] ) ) ) ? 'On' : 'Off';
542 - $current_settings['default'] = array(
543 - 'weekdays' => wpbc_availability_general__validate_working_time_weekdays( $post_data, 'booking_working_time_default' ),
544 - );
695 + $default_weekdays = wpbc_availability_general__validate_working_time_weekdays( $post_data, 'booking_working_time_default' );
696 + if ( is_wp_error( $default_weekdays ) ) {
697 + return $default_weekdays;
698 + }
699 +
700 + $resource_weekdays = isset( $current_settings['resources'][ $resource_id ]['weekdays'] )
701 + ? $current_settings['resources'][ $resource_id ]['weekdays']
702 + : $current_settings['default']['weekdays'];
703 + if ( 'custom' === $resource_mode ) {
704 + $resource_weekdays = wpbc_availability_general__validate_working_time_weekdays( $post_data, 'booking_working_time_resource' );
705 + if ( is_wp_error( $resource_weekdays ) ) {
706 + return $resource_weekdays;
707 + }
708 + }
709 +
710 + $current_settings['enabled'] = ( isset( $post_data['booking_working_time_enabled'] ) && 'On' === sanitize_text_field( wp_unslash( $post_data['booking_working_time_enabled'] ) ) ) ? 'On' : 'Off';
711 + $current_settings['default'] = array(
712 + 'weekdays' => $default_weekdays,
713 + );
545 714
546 715 if ( $resource_id > 0 ) {
547 - $current_settings['resources'][ $resource_id ] = array(
548 - 'mode' => $resource_mode,
549 - 'weekdays' => wpbc_availability_general__validate_working_time_weekdays( $post_data, 'booking_working_time_resource' ),
550 - );
716 + $current_settings['resources'][ $resource_id ] = array(
717 + 'mode' => $resource_mode,
718 + 'weekdays' => $resource_weekdays,
719 + );
551 720 }
552 721
553 722 return wpbc_working_time__normalize_settings( $current_settings );
554 723 }
@@ -557,9 +726,9 @@
557 726 * Validate posted settings.
558 727 *
559 728 * @param array $post_data Raw post data.
560 729 *
561 - * @return array
730 + * @return array|WP_Error Validated settings or an error.
562 731 */
563 732 function wpbc_availability_general__validate_data( $post_data ) {
564 733
565 734 $cleaned = wpbc_availability_general__get_default_settings();
@@ -603,9 +772,12 @@
603 772 $cleaned[ $key ] = preg_match( '/^\d+d$/', $value ) ? $value : '';
604 773 }
605 774 }
606 775
607 - $cleaned['working_time'] = wpbc_availability_general__validate_working_time_data( $post_data );
776 + $cleaned['working_time'] = wpbc_availability_general__validate_working_time_data( $post_data );
777 + if ( is_wp_error( $cleaned['working_time'] ) ) {
778 + return $cleaned['working_time'];
779 + }
608 780
609 781 return $cleaned;
610 782 }
611 783
@@ -857,9 +1029,9 @@
857 1029
858 1030 /**
859 1031 * General Availability tab.
860 1032 */
861 -class WPBC_Page_Availability_General_Dedicated extends WPBC_Page_Structure {
1033 +class WPBC_Page_Availability_General_Dedicated extends WPBC_Page_Structure {
862 1034
863 1035 /**
864 1036 * Whether settings were saved during this request.
865 1037 *
@@ -864,9 +1036,16 @@
864 1036 * Whether settings were saved during this request.
865 1037 *
866 1038 * @var bool
867 1039 */
868 - private $is_updated = false;
1040 + private $is_updated = false;
1041 +
1042 + /**
1043 + * Validation failure retained for the non-AJAX form fallback.
1044 + *
1045 + * @var WP_Error|null
1046 + */
1047 + private $validation_error = null;
869 1048
870 1049 /**
871 1050 * Menu slug.
872 1051 *
@@ -936,10 +1115,15 @@
936 1115 if ( ! wpbc_is_mu_user_can_be_here( 'only_super_admin' ) || ! current_user_can( wpbc_availability_general__get_manage_cap() ) ) {
937 1116 return;
938 1117 }
939 1118
940 - $cleaned_data = wpbc_availability_general__validate_data( $_POST ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
941 - wpbc_availability_general__update_settings( $cleaned_data );
1119 + $cleaned_data = wpbc_availability_general__validate_data( $_POST ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1120 + if ( is_wp_error( $cleaned_data ) ) {
1121 + $this->validation_error = $cleaned_data;
1122 + return;
1123 + }
1124 +
1125 + wpbc_availability_general__update_settings( $cleaned_data );
942 1126
943 1127 $this->is_updated = true;
944 1128 }
945 1129
@@ -1019,9 +1203,12 @@
1019 1203 $is_buffer_available = class_exists( 'wpdev_bk_biz_m' );
1020 1204 $is_available_limit_available = class_exists( 'wpdev_bk_biz_m' );
1021 1205 $unavailable_weekdays = array();
1022 1206 $working_time_settings = wpbc_working_time__get_settings();
1023 - $working_time_default_settings = wpbc_working_time__get_default_settings();
1207 + $working_time_default_settings = wpbc_working_time__get_default_settings();
1208 + $working_time_options = wpbc_availability_general__get_working_time_options(
1209 + wpbc_availability_general__get_working_time_option_values( $working_time_settings )
1210 + );
1024 1211 $working_time_resource_id = wpbc_availability_general__get_preview_resource_id();
1025 1212 $open_section = wpbc_availability_general__get_open_section();
1026 1213 $working_time_resource = isset( $working_time_settings['resources'][ $working_time_resource_id ] )
1027 1214 ? $working_time_settings['resources'][ $working_time_resource_id ]
@@ -1037,13 +1224,18 @@
1037 1224 }
1038 1225
1039 1226 WPBC_UI_Sidebar_Panels::render_inspector_header( __( 'Schedule & Rules', 'booking' ), __( 'Availability rules for all calendars.', 'booking' ) );
1040 1227 ?>
1041 - <form method="post" id="<?php echo esc_attr( $form_name ); ?>" class="wpbc_ag_settings_form" data-wpbc-ag-settings-form="1">
1228 + <form method="post" id="<?php echo esc_attr( $form_name ); ?>" class="wpbc_ag_settings_form" data-wpbc-ag-settings-form="1">
1042 1229 <?php wp_nonce_field( 'wpbc_settings_page_' . $form_name ); ?>
1043 1230 <input type="hidden" name="is_form_submitted_<?php echo esc_attr( $form_name ); ?>" value="1" />
1044 - <div class="wpbc_bfb__inspector__body wpbc_ag_inspector_body">
1045 - <?php
1231 + <div class="wpbc_bfb__inspector__body wpbc_ag_inspector_body">
1232 + <?php if ( is_wp_error( $this->validation_error ) ) : ?>
1233 + <div class="wpbc_ag_notice wpbc_ag_notice_error" role="alert">
1234 + <?php echo esc_html( $this->validation_error->get_error_message() ); ?>
1235 + </div>
1236 + <?php endif; ?>
1237 + <?php
1046 1238 WPBC_UI_Sidebar_Panels::render_collapsible_group(
1047 1239 array(
1048 1240 'id' => 'wpbc_ag_weekdays_group',
1049 1241 'group' => 'general-availability-weekdays',
@@ -1109,9 +1301,9 @@
1109 1301 'group' => 'general-availability-working-time',
1110 1302 'title' => __( 'Working Time', 'booking' ),
1111 1303 'open' => ( 'working_time' === $open_section ),
1112 1304 ),
1113 - function () use ( $working_time_settings, $working_time_resource_id, $working_time_resource ) {
1305 + function () use ( $working_time_settings, $working_time_resource_id, $working_time_resource, $working_time_options ) {
1114 1306 ?>
1115 1307 <div class="wpbc_ag_notice wpbc_ag_working_time_notice"><?php esc_html_e( 'Working Time restricts only time-based bookings, such as rangetime, start/end time, or start/duration time fields.', 'booking' ); ?></div>
1116 1308 <input type="hidden" name="booking_working_time_resource_id" data-wpbc-working-time-resource-id="1" value="<?php echo esc_attr( $working_time_resource_id ); ?>" />
1117 1309 <label class="wpbc_ag_switch wpbc_ag_switch_card">
@@ -1122,9 +1314,9 @@
1122 1314
1123 1315 <div class="wpbc_ag_working_time_block">
1124 1316 <div class="wpbc_ag_scope_title"><?php esc_html_e( 'Default working time', 'booking' ); ?></div>
1125 1317 <p class="wpbc_ag_description"><?php esc_html_e( 'Used by all booking resources unless a resource override is configured below.', 'booking' ); ?></p>
1126 - <?php wpbc_availability_general__render_working_time_weekdays( 'booking_working_time_default', $working_time_settings['default']['weekdays'] ); ?>
1318 + <?php wpbc_availability_general__render_working_time_weekdays( 'booking_working_time_default', $working_time_settings['default']['weekdays'], $working_time_options ); ?>
1127 1319 </div>
1128 1320
1129 1321 <div class="wpbc_ag_working_time_block wpbc_ag_working_time_resource_block" data-wpbc-working-time-resource-block="1">
1130 1322 <div class="wpbc_ag_scope_title"><?php esc_html_e( 'Selected resource override', 'booking' ); ?></div>
@@ -1134,9 +1326,9 @@
1134 1326 <label><input type="radio" name="booking_working_time_resource_mode" value="custom" <?php checked( $working_time_resource['mode'], 'custom' ); ?> /> <?php esc_html_e( 'Use custom working time', 'booking' ); ?></label>
1135 1327 <label><input type="radio" name="booking_working_time_resource_mode" value="disabled" <?php checked( $working_time_resource['mode'], 'disabled' ); ?> /> <?php esc_html_e( 'Do not restrict this resource by working time', 'booking' ); ?></label>
1136 1328 </div>
1137 1329 <div class="wpbc_ag_working_time_custom" data-wpbc-working-time-resource-custom="1">
1138 - <?php wpbc_availability_general__render_working_time_weekdays( 'booking_working_time_resource', $working_time_resource['weekdays'] ); ?>
1330 + <?php wpbc_availability_general__render_working_time_weekdays( 'booking_working_time_resource', $working_time_resource['weekdays'], $working_time_options ); ?>
1139 1331 </div>
1140 1332 </div>
1141 1333 <?php
1142 1334 }