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/publish/wpbc-create-pages.php +547 -245 11.4.3 → 11.9 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * @version 1.0
4 4 * @package Booking Calendar
@@ -28,8 +28,13 @@
28 28 * @return false|int - ID of the page.
29 29 */
30 30 function wpbc_create_page( $page_params = array() ){ // FixIn: 9.6.2.10.
31 31
32 + /* Live demos must never create WordPress content through Booking Calendar. */
33 + if ( wpbc_is_booking_form_publishing_restricted() ) {
34 + return false;
35 + }
36 +
32 37 global $wp_rewrite;
33 38 if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1.
34 39 return false;
35 40 }
@@ -369,10 +374,10 @@
369 374 * Create new page or add to existing page the shortcode
370 375 *
371 376 * @param array $params
372 377 *
373 - * @return array success: [ 'result' => true, 'relative_url' => $relative_post_url, 'message' => __( 'Booking form shortcode embedded into the page.', 'booking' ) ]
374 - * failed: [ 'result' => false, 'message' => __( 'We can not embed booking form shortcode into the page.', 'booking' ) ]
378 + * @return array Success or failure response. Publishing restrictions return a
379 + * failure before WordPress page lookup or mutation.
375 380 *
376 381 * Example:
377 382 * $result_arr = wpbc_add_shortcode_into_page( array(
378 383 * 'shortcode' => '[booking resource_id=1]',
@@ -379,8 +384,15 @@
379 384 * 'post_title' => 'Booking Form'
380 385 * ) );
381 386 */
382 387 function wpbc_add_shortcode_into_page( $params = array() ) {
388 + /* Enforce the publishing policy at the canonical writer for every caller. */
389 + if ( wpbc_is_booking_form_publishing_restricted() ) {
390 + return array(
391 + 'result' => false,
392 + 'message' => __( 'In the demo versions this operation is not allowed.', 'booking' ),
393 + );
394 + }
383 395
384 396 $defaults = array(
385 397 'page_post_name' => '', // 'wpbc-booking',
386 398 'post_title' => esc_html( __( 'Booking Form', 'booking' ) ),
@@ -531,40 +543,48 @@
531 543 * @return array
532 544 */
533 545 function wpbc_get_activation_booking_form_page_configs() {
534 546
535 - return array(
536 - 'full_day_booking' => array(
537 - 'template_key' => 'dates_advanced_3_steps_review_with_hints',
538 - 'form_slug' => 'full_day_booking',
539 - 'form_title' => esc_html__( 'Full Day Booking Form', 'booking' ),
540 - 'page_slug' => 'wp-booking-calendar-full-day',
541 - 'page_title' => esc_html__( 'Full Day Booking', 'booking' ),
542 - 'button_title' => esc_html__( 'Full day booking form', 'booking' ),
547 + return array(
548 + 'full_day_booking' => array(
549 + 'template_key' => 'dates_2_columns_hints_full_days', // 'dates_form_with_inline_hints', // FixIn: 11.8.1.1.
550 + 'form_slug' => 'full_day_booking',
551 + 'form_title' => esc_html__( 'Full Day Booking Form', 'booking' ),
552 + 'page_slug' => 'booking-calendar-full-day',
553 + 'legacy_page_slugs' => array( 'wp-booking-calendar-full-day' ),
554 + 'page_title' => esc_html__( 'Full Day Booking', 'booking' ),
555 + 'button_title' => esc_html__( 'Full day booking form', 'booking' ),
556 + ),
557 + 'time_slots_booking' => array(
558 + 'template_key' => 'time_slots_2_columns_hints',
559 + 'form_slug' => 'time_slots_booking',
560 + 'form_title' => esc_html__( 'Time Slots Booking Form', 'booking' ),
561 + 'page_slug' => 'booking-calendar-time-slots',
562 + 'legacy_page_slugs' => array( 'wp-booking-calendar-time-slots' ),
563 + 'page_title' => esc_html__( 'Time Slots Booking', 'booking' ),
564 + 'button_title' => esc_html__( 'Time slots booking form', 'booking' ),
543 565 ),
544 - 'time_slots_booking' => array(
545 - 'template_key' => 'time_slots_20_min_3_steps_review_with_hints',
546 - 'form_slug' => 'time_slots_booking',
547 - 'form_title' => esc_html__( 'Time Slots Booking Form', 'booking' ),
548 - 'page_slug' => 'wp-booking-calendar-time-slots',
549 - 'page_title' => esc_html__( 'Time Slots Booking', 'booking' ),
550 - 'button_title' => esc_html__( 'Time slots booking form', 'booking' ),
551 - ),
552 566 'time_appointments_booking' => array(
553 567 'template_key' => 'time_appointments_3_steps_review_with_hints',
554 568 'form_slug' => 'time_appointments_booking',
555 569 'form_title' => esc_html__( 'Time Appointments Booking Form', 'booking' ),
556 - 'page_slug' => 'wp-booking-calendar-time-appointments',
557 - 'page_title' => esc_html__( 'Time Appointments Booking', 'booking' ),
558 - 'button_title' => esc_html__( 'Time appointments booking form', 'booking' ),
570 + 'create_page' => false,
571 + ),
572 + 'appointment_services_booking' => array(
573 + 'template_key' => 'appointments_services_selection_summary',
574 + 'form_slug' => 'appointment_services_booking',
575 + 'form_title' => esc_html__( 'Appointment Services Booking Form', 'booking' ),
576 + 'create_page' => false,
577 + 'assign_to_default_appointment_service' => true,
559 578 ),
560 - 'contact_form' => array(
561 - 'template_key' => 'contact_form_simple',
562 - 'form_slug' => 'contact_form',
563 - 'form_title' => esc_html__( 'Contact Form', 'booking' ),
564 - 'page_slug' => 'wp-booking-calendar-contact',
565 - 'page_title' => esc_html__( 'Contact Form', 'booking' ),
566 - 'button_title' => esc_html__( 'Contact form', 'booking' ),
579 + 'contact_form' => array(
580 + 'template_key' => 'contact_form_simple',
581 + 'form_slug' => 'contact_form',
582 + 'form_title' => esc_html__( 'Contact Form', 'booking' ),
583 + 'page_slug' => 'booking-calendar-contact',
584 + 'legacy_page_slugs' => array( 'wp-booking-calendar-contact' ),
585 + 'page_title' => esc_html__( 'Contact Form', 'booking' ),
586 + 'button_title' => esc_html__( 'Contact form', 'booking' ),
567 587 ),
568 588 );
569 589 }
570 590
@@ -569,8 +589,241 @@
569 589 }
570 590
571 591
572 592 /**
593 + * Get starter page definitions created during plugin activation.
594 + *
595 + * Legacy starter pages keep using their dedicated custom booking forms. The
596 + * old Time Appointments form and the dedicated Appointment Service form are
597 + * form-only fixtures because the Appointment workflow has one canonical page.
598 + *
599 + * @return array Starter page definitions keyed by stable purpose.
600 + */
601 +function wpbc_get_activation_booking_page_configs() {
602 +
603 + $page_configs = wpbc_get_activation_booking_form_page_configs();
604 +
605 + foreach ( $page_configs as $page_key => $page_config ) {
606 + if ( isset( $page_config['create_page'] ) && false === (bool) $page_config['create_page'] ) {
607 + unset( $page_configs[ $page_key ] );
608 + continue;
609 + }
610 +
611 + $form_slug = '';
612 + if ( isset( $page_config['form_slug'] ) ) {
613 + $form_slug = sanitize_text_field( (string) $page_config['form_slug'] );
614 + }
615 +
616 + if ( '' === $form_slug ) {
617 + unset( $page_configs[ $page_key ] );
618 + continue;
619 + }
620 +
621 + $shortcode = "[booking resource_id=1 form_type='{$form_slug}']";
622 + $page_configs[ $page_key ]['shortcode'] = $shortcode;
623 + $page_configs[ $page_key ]['shortcode_checks'] = array(
624 + $shortcode,
625 + '[booking resource_id=1 form_type="' . $form_slug . '"]',
626 + );
627 + $page_configs[ $page_key ]['resource_id'] = 1;
628 + }
629 +
630 + $page_configs['appointment_booking'] = array(
631 + 'page_slug' => 'booking-calendar-appointment',
632 + 'legacy_page_slugs' => array( 'wpbc-appointment-booking' ),
633 + 'page_title' => esc_html__( 'Book an Appointment', 'booking' ),
634 + 'button_title' => esc_html__( 'Appointment booking form', 'booking' ),
635 + 'shortcode' => '[booking_appointment]',
636 + 'shortcode_checks' => array( '[booking_appointment]', '[booking_appointment ' ),
637 + 'resource_id' => 0,
638 + );
639 + $page_configs['resource_selector_booking'] = array(
640 + 'page_slug' => 'booking-calendar-resource-selection',
641 + 'legacy_page_slugs' => array(),
642 + 'page_title' => esc_html__( 'Resource Selection', 'booking' ),
643 + 'button_title' => esc_html__( 'Resource selection', 'booking' ),
644 + 'shortcode' => '[booking_resource_selector]',
645 + 'shortcode_checks' => array( '[booking_resource_selector]', '[booking_resource_selector ' ),
646 + 'resource_id' => 0,
647 + );
648 +
649 + return $page_configs;
650 +}
651 +
652 +
653 +/**
654 + * Get the Free Booking Received page definition used during initial activation.
655 + *
656 + * The legacy slug remains lookup-only so a clean reinstall can reuse a retained
657 + * page without making legacy URLs canonical for new installations.
658 + *
659 + * @return array Confirmation page definition with canonical and legacy slugs.
660 + */
661 +function wpbc_get_activation_confirmation_page_config() {
662 +
663 + return array(
664 + 'page_slug' => 'booking-calendar-confirmation',
665 + 'legacy_page_slugs' => array( 'wpbc-booking-received' ),
666 + );
667 +}
668 +
669 +
670 +/**
671 + * Get the Personal-edition customer page definitions used during activation.
672 + *
673 + * @return array Personal page definitions keyed by stable purpose.
674 + */
675 +function wpbc_get_activation_personal_page_configs() {
676 +
677 + return array(
678 + 'manage_booking' => array(
679 + 'page_slug' => 'booking-calendar-manage-booking',
680 + 'legacy_page_slugs' => array( 'wpbc-my-booking' ),
681 + 'page_title' => esc_html__( 'My Booking', 'booking' ),
682 + 'shortcode' => '[bookingedit]',
683 + 'option_name' => 'booking_url_bookings_edit_by_visitors',
684 + ),
685 + 'my_bookings' => array(
686 + 'page_slug' => 'booking-calendar-my-bookings',
687 + 'legacy_page_slugs' => array( 'wpbc-my-bookings-listing' ),
688 + 'page_title' => esc_html__( 'My Bookings Listing', 'booking' ),
689 + 'shortcode' => '[bookingcustomerlisting]',
690 + 'option_name' => 'booking_url_bookings_listing_by_customer',
691 + ),
692 + );
693 +}
694 +
695 +
696 +/**
697 + * Get the Business Small payment-result page definitions used during activation.
698 + *
699 + * @return array Payment-result definitions keyed by stable outcome.
700 + */
701 +function wpbc_get_activation_payment_page_configs() {
702 +
703 + return array(
704 + 'success' => array(
705 + 'page_slug' => 'booking-calendar-payment-success',
706 + 'legacy_page_slugs' => array( 'wpbc-booking-payment-successful' ),
707 + 'page_title' => esc_html__( 'Booking Payment Confirmation', 'booking' ),
708 + 'page_content' => esc_html__( 'Thank you for your booking. Your payment for the booking has been successfully received.', 'booking' )
709 + . "\r\n\r\n[booking_confirm]",
710 + 'required_shortcode' => '[booking_confirm]',
711 + 'default_url' => '/successful',
712 + 'option_names' => array(
713 + 'booking_stripe_v3_order_successful',
714 + 'booking_paypal_std_co_order_successful',
715 + 'booking_paypal_return_url',
716 + 'booking_authorizenet_order_successful',
717 + 'booking_sage_order_successful',
718 + 'booking_redsys_order_successful',
719 + 'booking_ideal_return_url',
720 + 'booking_ipay88_return_url',
721 + ),
722 + ),
723 + 'failed' => array(
724 + 'page_slug' => 'booking-calendar-payment-failed',
725 + 'legacy_page_slugs' => array( 'wpbc-booking-payment-failed' ),
726 + 'page_title' => esc_html__( 'Booking Payment Failed', 'booking' ),
727 + 'page_content' => esc_html__( 'Payment Unsuccessful. Please contact us for assistance.', 'booking' ),
728 + 'required_shortcode' => '',
729 + 'default_url' => '/failed',
730 + 'option_names' => array(
731 + 'booking_stripe_v3_order_failed',
732 + 'booking_paypal_std_co_order_failed',
733 + 'booking_paypal_cancel_return_url',
734 + 'booking_authorizenet_order_failed',
735 + 'booking_sage_order_failed',
736 + 'booking_redsys_order_failed',
737 + 'booking_ideal_cancel_return_url',
738 + 'booking_ipay88_cancel_return_url',
739 + ),
740 + ),
741 + );
742 +}
743 +
744 +
745 +/**
746 + * Check whether an activation payment URL still contains its replaceable default.
747 + *
748 + * Missing options and the released placeholder paths may be connected to a
749 + * newly eligible payment page. Every other value is treated as administrator
750 + * configuration and must remain unchanged.
751 + *
752 + * @param mixed $configured_url Saved payment return URL, or false when absent.
753 + * @param string $default_url Released relative placeholder URL.
754 + *
755 + * @return bool True when activation may store the eligible payment page URL.
756 + */
757 +function wpbc_should_update_activation_payment_url( $configured_url, $default_url ) {
758 +
759 + if ( false === $configured_url ) {
760 + return true;
761 + }
762 +
763 + return (string) $default_url === wpbc_make_link_relative( $configured_url );
764 +}
765 +
766 +
767 +/**
768 + * Find an existing activation-owned page by its canonical or legacy slug.
769 + *
770 + * Canonical slugs are checked first. Legacy aliases are used only to preserve
771 + * existing pages and prevent duplicates after a full plugin-data reset.
772 + *
773 + * @param string $page_slug Canonical page slug.
774 + * @param array $legacy_page_slugs Previously released page slugs.
775 + *
776 + * @return WP_Post|null Existing WordPress page, or null when no slug matches.
777 + */
778 +function wpbc_get_activation_page_by_slugs( $page_slug, $legacy_page_slugs = array() ) {
779 +
780 + $page_slugs = array_merge( array( $page_slug ), (array) $legacy_page_slugs );
781 + $page_slugs = array_unique( array_filter( array_map( 'sanitize_title', $page_slugs ) ) );
782 +
783 + foreach ( $page_slugs as $candidate_page_slug ) {
784 + $wp_post = get_page_by_path( $candidate_page_slug, OBJECT, 'page' );
785 +
786 + if ( $wp_post instanceof WP_Post ) {
787 + return $wp_post;
788 + }
789 + }
790 +
791 + return null;
792 +}
793 +
794 +
795 +/**
796 + * Get the first published activation page matching a canonical or legacy slug.
797 + *
798 + * This read-only lookup is separate from the activation writer lookup because
799 + * activation must recognize retained non-published pages to avoid duplicates,
800 + * while public-page navigation must never advertise an inaccessible draft or
801 + * trashed canonical page when a published legacy page is still available.
802 + *
803 + * @param string $page_slug Canonical activation page slug.
804 + * @param array $legacy_page_slugs Previously released lookup-only slugs.
805 + *
806 + * @return WP_Post|null Published page, or null when no public match exists.
807 + */
808 +function wpbc_get_published_activation_page_by_slugs( $page_slug, $legacy_page_slugs = array() ) {
809 +
810 + $page_slugs = array_merge( array( $page_slug ), (array) $legacy_page_slugs );
811 + $page_slugs = array_unique( array_filter( array_map( 'sanitize_title', $page_slugs ) ) );
812 +
813 + foreach ( $page_slugs as $candidate_page_slug ) {
814 + $wp_post = get_page_by_path( $candidate_page_slug, OBJECT, 'page' );
815 +
816 + if ( $wp_post instanceof WP_Post && 'publish' === $wp_post->post_status ) {
817 + return $wp_post;
818 + }
819 + }
820 +
821 + return null;
822 +}
823 +
824 +
825 +/**
573 826 * Get a bundled BFB template record by template key.
574 827 *
575 828 * @param string $template_key Template key.
576 829 *
@@ -604,14 +857,14 @@
604 857 return array();
605 858 }
606 859
607 860
608 -/**
609 - * Create starter custom booking forms from bundled BFB templates.
861 +/**
862 + * Create starter custom booking forms from bundled BFB templates.
610 863 *
611 864 * @return bool
612 865 */
613 -function wpbc_create_activation_custom_booking_forms() {
866 +function wpbc_create_activation_custom_booking_forms() {
614 867
615 868 if (
616 869 ! function_exists( 'wpbc_is_table_exists' ) ||
617 870 ! wpbc_is_table_exists( 'booking_form_structures' ) ||
@@ -683,9 +936,105 @@
683 936 }
684 937 }
685 938
686 939 return $is_created;
687 -}
940 +}
941 +
942 +
943 +/**
944 + * Return the ordered activation-page level for a Booking Calendar edition.
945 + *
946 + * The ordering is intentionally limited to product editions. Page groups use
947 + * these levels to determine whether a paid activation has crossed the edition
948 + * boundary that first makes those pages available.
949 + *
950 + * @param string $edition_id Booking Calendar edition identifier.
951 + *
952 + * @return int Edition level, or -1 when the identifier is not supported.
953 + */
954 +function wpbc_get_activation_page_edition_level( $edition_id ) {
955 +
956 + $edition_levels = array(
957 + 'free' => 0,
958 + 'personal' => 1,
959 + 'biz_s' => 2,
960 + 'biz_m' => 3,
961 + 'biz_l' => 4,
962 + 'multiuser' => 5,
963 + );
964 +
965 + $edition_id = (string) $edition_id;
966 +
967 + return isset( $edition_levels[ $edition_id ] ) ? $edition_levels[ $edition_id ] : -1;
968 +}
969 +
970 +
971 +/**
972 + * Check whether a paid-edition transition newly unlocks one page group.
973 + *
974 + * This pure comparison keeps Free-to-Pro, lower-to-higher, reactivation,
975 + * update, and downgrade behavior deterministic and independently testable.
976 + *
977 + * @param string $previous_edition_id Previously provisioned or detected edition.
978 + * @param string $current_edition_id Edition active during this activation.
979 + * @param string $required_edition_id First edition that owns the page group.
980 + *
981 + * @return bool True when this activation crosses the required edition boundary.
982 + */
983 +function wpbc_is_activation_page_edition_transition( $previous_edition_id, $current_edition_id, $required_edition_id ) {
984 +
985 + $previous_edition_level = wpbc_get_activation_page_edition_level( $previous_edition_id );
986 + $current_edition_level = wpbc_get_activation_page_edition_level( $current_edition_id );
987 + $required_edition_level = wpbc_get_activation_page_edition_level( $required_edition_id );
988 +
989 + if ( 0 > $previous_edition_level || 0 > $current_edition_level || 1 > $required_edition_level ) {
990 + return false;
991 + }
992 +
993 + return $previous_edition_level < $required_edition_level
994 + && $required_edition_level <= $current_edition_level;
995 +}
996 +
997 +
998 +/**
999 + * Check whether activation-owned WordPress pages may be provisioned.
1000 + *
1001 + * Free-owned pages remain restricted to the immutable first-Free-install
1002 + * decision. Paid page groups can additionally opt into the exact Pro edition
1003 + * transition that first makes them available. The Pro activation layer owns
1004 + * that transition state and exposes it through a narrow filter; normal Free or
1005 + * Pro updates therefore remain fail-closed.
1006 + *
1007 + * @param string $required_edition_id First edition that owns the page group.
1008 + *
1009 + * @return bool True only during the qualifying initial activation request.
1010 + */
1011 +function wpbc_should_create_activation_pages( $required_edition_id = 'free' ) {
1012 + $required_edition_id = (string) $required_edition_id;
1013 + $required_edition_level = wpbc_get_activation_page_edition_level( $required_edition_id );
1014 +
1015 + if ( 0 > $required_edition_level ) {
1016 + return false;
1017 + }
1018 +
1019 + if ( function_exists( 'wpbc_is_plugin_initial_install' ) && wpbc_is_plugin_initial_install() ) {
1020 + return true;
1021 + }
1022 +
1023 + if ( 0 === $required_edition_level ) {
1024 + return false;
1025 + }
1026 +
1027 + /**
1028 + * Filter whether the current paid-edition activation newly owns a page group.
1029 + *
1030 + * @since 11.8.1
1031 + *
1032 + * @param bool $should_create_pages Fail-closed default decision.
1033 + * @param string $required_edition_id First edition that owns the page group.
1034 + */
1035 + return (bool) apply_filters( 'wpbc_should_create_paid_edition_activation_pages', false, $required_edition_id );
1036 +}
688 1037
689 1038
690 1039 /**
691 1040 * Build starter page content with a booking shortcode.
@@ -729,9 +1078,23 @@
729 1078 // -----------------------------------------------------------------------------------------------------------------
730 1079
731 1080 wpbc_create_activation_custom_booking_forms();
732 1081
733 - $configs = wpbc_get_activation_booking_form_page_configs();
1082 + /**
1083 + * Fires after activation starter custom forms are available.
1084 + *
1085 + * Appointment Services uses this boundary to finish its pending starter
1086 + * Service seed with the newly created form ID.
1087 + *
1088 + * @since 11.5.0
1089 + */
1090 + do_action( 'wpbc_activation_custom_booking_forms_created' );
1091 +
1092 + if ( ! wpbc_should_create_activation_pages() ) {
1093 + return;
1094 + }
1095 +
1096 + $configs = wpbc_get_activation_booking_page_configs();
734 1097 if ( empty( $configs ) || ! is_array( $configs ) ) {
735 1098 return;
736 1099 }
737 1100
@@ -738,28 +1101,36 @@
738 1101 $front_page_id = 0;
739 1102
740 1103 foreach ( $configs as $config ) {
741 1104
742 - $form_slug = sanitize_text_field( (string) $config['form_slug'] );
743 - $shortcode = "[booking resource_id=1 form_type='{$form_slug}']";
744 - $content = wpbc_get_activation_booking_page_content( $shortcode );
1105 + $shortcode = isset( $config['shortcode'] ) ? trim( (string) $config['shortcode'] ) : '';
1106 + $shortcode_checks = isset( $config['shortcode_checks'] ) && is_array( $config['shortcode_checks'] )
1107 + ? $config['shortcode_checks']
1108 + : array( $shortcode );
1109 + $resource_id = isset( $config['resource_id'] ) ? absint( $config['resource_id'] ) : 0;
745 1110
746 - $result_arr = wpbc_add_shortcode_into_page(
747 - array(
748 - 'page_post_name' => $config['page_slug'],
749 - 'post_title' => $config['page_title'],
1111 + if ( '' === $shortcode ) {
1112 + continue;
1113 + }
1114 +
1115 + $content = wpbc_get_activation_booking_page_content( $shortcode );
1116 + $legacy_page_slugs = isset( $config['legacy_page_slugs'] ) ? (array) $config['legacy_page_slugs'] : array();
1117 + $existing_page = wpbc_get_activation_page_by_slugs( $config['page_slug'], $legacy_page_slugs );
1118 +
1119 + $result_arr = wpbc_add_shortcode_into_page(
1120 + array(
1121 + 'page_post_name' => $config['page_slug'],
1122 + 'page_id' => $existing_page instanceof WP_Post ? $existing_page->ID : 0,
1123 + 'post_title' => $config['page_title'],
750 1124 'shortcode' => $content,
751 - 'check_exist_shortcode' => array(
752 - $shortcode,
753 - '[booking resource_id=1 form_type="' . $form_slug . '"]',
754 - ),
755 - 'resource_id' => 1,
1125 + 'check_exist_shortcode' => $shortcode_checks,
1126 + 'resource_id' => $resource_id,
756 1127 )
757 - );
758 -
759 - if ( WPBC_IS_PLAYGROUND && empty( $front_page_id ) && ! empty( $result_arr['relative_url'] ) ) {
760 - $wp_post = get_page_by_path( $config['page_slug'] );
761 - if ( ! empty( $wp_post ) ) {
1128 + );
1129 +
1130 + if ( WPBC_IS_PLAYGROUND && empty( $front_page_id ) && ! empty( $result_arr['relative_url'] ) ) {
1131 + $wp_post = wpbc_get_activation_page_by_slugs( $config['page_slug'], $legacy_page_slugs );
1132 + if ( ! empty( $wp_post ) ) {
762 1133 $front_page_id = $wp_post->ID;
763 1134 }
764 1135 }
765 1136 }
@@ -780,29 +1151,39 @@
780 1151 */
781 1152 function wpbc_get_published_activation_booking_pages() {
782 1153
783 1154 $pages = array();
784 - $configs = wpbc_get_activation_booking_form_page_configs();
1155 + $configs = wpbc_get_activation_booking_page_configs();
785 1156
786 1157 if ( empty( $configs ) || ! is_array( $configs ) ) {
787 1158 return $pages;
788 1159 }
789 1160
790 - foreach ( $configs as $key => $config ) {
1161 + foreach ( $configs as $key => $config ) {
1162 +
1163 + $legacy_page_slugs = isset( $config['legacy_page_slugs'] ) ? (array) $config['legacy_page_slugs'] : array();
1164 + $wp_post = wpbc_get_published_activation_page_by_slugs( $config['page_slug'], $legacy_page_slugs );
1165 + if ( ! ( $wp_post instanceof WP_Post ) ) {
1166 + continue;
1167 + }
791 1168
792 - $wp_post = get_page_by_path( $config['page_slug'] );
793 - if ( empty( $wp_post ) ) {
794 - continue;
1169 + $shortcode_checks = isset( $config['shortcode_checks'] ) && is_array( $config['shortcode_checks'] )
1170 + ? $config['shortcode_checks']
1171 + : array();
1172 + $is_shortcode_found = false;
1173 +
1174 + foreach ( $shortcode_checks as $shortcode_check ) {
1175 + if ( '' === (string) $shortcode_check ) {
1176 + continue;
1177 + }
1178 +
1179 + if ( wpbc_is_shortcode_exist_in_page_with_id( $wp_post->ID, $shortcode_check ) ) {
1180 + $is_shortcode_found = true;
1181 + break;
1182 + }
795 1183 }
796 1184
797 - $form_slug = sanitize_text_field( (string) $config['form_slug'] );
798 - $shortcode_single_quote = "[booking resource_id=1 form_type='{$form_slug}']";
799 - $shortcode_double_quote = '[booking resource_id=1 form_type="' . $form_slug . '"]';
800 -
801 - if (
802 - ! wpbc_is_shortcode_exist_in_page_with_id( $wp_post->ID, $shortcode_single_quote ) &&
803 - ! wpbc_is_shortcode_exist_in_page_with_id( $wp_post->ID, $shortcode_double_quote )
804 - ) {
1185 + if ( ! $is_shortcode_found ) {
805 1186 continue;
806 1187 }
807 1188
808 1189 $post_url = get_permalink( $wp_post->ID );
@@ -829,11 +1210,15 @@
829 1210 * @param $default_options_to_add
830 1211 *
831 1212 * @return void
832 1213 */
833 -function wpbc_create_page_thank_you( $default_options_to_add ) { // FixIn: 9.6.2.11.
834 -
835 - global $wp_rewrite;
1214 +function wpbc_create_page_thank_you( $default_options_to_add ) { // FixIn: 9.6.2.11.
1215 +
1216 + if ( ! wpbc_should_create_activation_pages() ) {
1217 + return false;
1218 + }
1219 +
1220 + global $wp_rewrite;
836 1221 if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1.
837 1222
838 1223 // Maybe it was not init, yet
839 1224 if ( ! has_action( 'init', 'wpbc_create_page_thank_you' ) ) {
@@ -852,20 +1237,24 @@
852 1237 && ( empty( get_page_by_path( 'thank-you' ) ) ) // FixIn: 9.9.0.27.
853 1238 )
854 1239 || ( '/' == wpbc_make_link_relative( get_bk_option( 'booking_thank_you_page_URL' ) ) )
855 1240 ){
856 - $wp_post = get_page_by_path( 'wpbc-booking-received' );
1241 + $confirmation_page_config = wpbc_get_activation_confirmation_page_config();
1242 + $wp_post = wpbc_get_activation_page_by_slugs(
1243 + $confirmation_page_config['page_slug'],
1244 + $confirmation_page_config['legacy_page_slugs']
1245 + );
857 1246
858 1247 $post_url = '';
859 1248
860 1249 if ( empty( $wp_post ) ) { // No default page. Create it.
861 1250
862 - $page_params = array(
863 - 'post_title' => esc_html( __( 'Booking Received', 'booking' ) ),
864 - 'post_content' => esc_html( __( 'Thank you for your booking. Your booking has been successfully received.', 'booking' ) )
865 - . "\r\n" . ' [booking_confirm]',
866 - 'post_name' => 'wpbc-booking-received'
867 - );
1251 + $page_params = array(
1252 + 'post_title' => esc_html( __( 'Booking Received', 'booking' ) ),
1253 + 'post_content' => esc_html( __( 'Thank you for your booking. Your booking has been successfully received.', 'booking' ) )
1254 + . "\r\n" . ' [booking_confirm]',
1255 + 'post_name' => $confirmation_page_config['page_slug'],
1256 + );
868 1257 $post_id = wpbc_create_page( $page_params );
869 1258
870 1259 if ( ! empty( $post_id ) ) {
871 1260 $post_url = wpbc_make_link_relative( get_permalink( $post_id ) );
@@ -899,11 +1288,15 @@
899 1288 * to some pages different from homepage.
900 1289 *
901 1290 * @return void
902 1291 */
903 -function wpbc_create_page_bookingedit(){ // FixIn: 9.6.2.10.
904 -
905 - global $wp_rewrite;
1292 +function wpbc_create_page_bookingedit(){ // FixIn: 9.6.2.10.
1293 +
1294 + if ( ! wpbc_should_create_activation_pages( 'personal' ) ) {
1295 + return false;
1296 + }
1297 +
1298 + global $wp_rewrite;
906 1299 if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1.
907 1300 // Maybe it was not init, yet
908 1301 if ( ! has_action( 'init', 'wpbc_create_page_bookingedit' ) ) {
909 1302 add_action( 'init', 'wpbc_create_page_bookingedit', 99 ); // <- priority to load it last
@@ -910,182 +1303,91 @@
910 1303 }
911 1304 return false;
912 1305 }
913 1306
914 - // Booking Edit page - set default page and URL ---------------------------------------------------------------
915 - $url_booking_edit = get_bk_option( 'booking_url_bookings_edit_by_visitors' );
916 - if (
917 - ( site_url() == $url_booking_edit )
918 - && ( empty( get_page_by_path( 'wpbc-my-booking' ) ) )
919 - ){
920 - $page_params = array(
921 - 'post_content' => '[bookingedit]', // The post content
922 - 'post_name' => 'wpbc-my-booking', // sanitize_title( $post_title )
923 - 'post_title' => esc_html__( 'My Booking', 'booking' ) // Title
924 - );
1307 + $page_configs = wpbc_get_activation_personal_page_configs();
1308 +
1309 + foreach ( $page_configs as $page_config ) {
1310 + $configured_page_url = get_bk_option( $page_config['option_name'] );
1311 + $existing_page = wpbc_get_activation_page_by_slugs(
1312 + $page_config['page_slug'],
1313 + $page_config['legacy_page_slugs']
1314 + );
1315 +
1316 + if ( site_url() === $configured_page_url && ! ( $existing_page instanceof WP_Post ) ) {
1317 + $page_id = wpbc_create_page(
1318 + array(
1319 + 'post_content' => $page_config['shortcode'],
1320 + 'post_name' => $page_config['page_slug'],
1321 + 'post_title' => $page_config['page_title'],
1322 + )
1323 + );
1324 +
1325 + if ( ! empty( $page_id ) ) {
1326 + update_bk_option( $page_config['option_name'], get_permalink( $page_id ) );
1327 + }
1328 + } elseif (
1329 + ( site_url() === $configured_page_url || empty( $configured_page_url ) )
1330 + && $existing_page instanceof WP_Post
1331 + ) {
1332 + update_bk_option( $page_config['option_name'], get_permalink( $existing_page->ID ) );
1333 + }
1334 +
1335 + $relative_page_url = wpbc_make_link_relative( get_bk_option( $page_config['option_name'] ) );
1336 + wpbc_add_shortcode_to_exist_page( $relative_page_url, $page_config['shortcode'] );
1337 + }
925 1338
926 - $post_id = wpbc_create_page( $page_params );
927 -
928 - if ( ! empty( $post_id ) ) {
929 - $post_url = get_permalink( $post_id );
930 - update_bk_option( 'booking_url_bookings_edit_by_visitors', $post_url );
931 - }
932 - } else if (
933 - (
934 - ( site_url() == $url_booking_edit )
935 - || ( empty( $url_booking_edit ) )
936 - )
937 - && ( ! empty( get_page_by_path( 'wpbc-my-booking' ) ) )
938 - ){
939 - $wp_post = get_page_by_path( 'wpbc-my-booking' );
940 - if ( ! empty( $wp_post ) ) {
941 - update_bk_option( 'booking_url_bookings_edit_by_visitors', get_permalink( $wp_post->ID ) );
942 - }
943 - }
944 -
945 - // -----------------------------------------------------------------------------------------------------------------
946 - // Check if existing page has our shortcode
947 - // -----------------------------------------------------------------------------------------------------------------
948 - $booking_edit_relative_url = wpbc_make_link_relative( get_bk_option( 'booking_url_bookings_edit_by_visitors' ) );
949 - $is_added = wpbc_add_shortcode_to_exist_page( $booking_edit_relative_url, '[bookingedit]' );
950 -
951 -
952 - // =================================================================================================================
953 - // =================================================================================================================
954 - // =================================================================================================================
955 -
956 -
957 - // Booking Listing page - set default page and URL ---------------------------------------------------------------
958 - $url_booking_edit = get_bk_option( 'booking_url_bookings_listing_by_customer' );
959 - if (
960 - ( site_url() == $url_booking_edit )
961 - && ( empty( get_page_by_path( 'wpbc-my-bookings-listing' ) ) )
962 - ){
963 -
964 - $page_params = array(
965 - 'post_content' => '[bookingcustomerlisting]', // The post content
966 - 'post_name' => 'wpbc-my-bookings-listing', // sanitize_title( $post_title )
967 - 'post_title' => esc_html__( 'My Bookings Listing', 'booking' ) // Title
968 - );
969 -
970 - $post_id = wpbc_create_page( $page_params );
971 -
972 - if ( ! empty( $post_id ) ) {
973 - $post_url = get_permalink( $post_id );
974 - update_bk_option( 'booking_url_bookings_listing_by_customer', $post_url );
975 - }
976 - } else if (
977 - (
978 - ( site_url() == $url_booking_edit )
979 - || ( empty( $url_booking_edit ) )
980 - )
981 - && ( ! empty( get_page_by_path( 'wpbc-my-bookings-listing' ) ) )
982 - ){
983 - $wp_post = get_page_by_path( 'wpbc-my-bookings-listing' );
984 - if ( ! empty( $wp_post ) ){
985 - update_bk_option( 'booking_url_bookings_listing_by_customer', get_permalink( $wp_post->ID ) );
986 - }
987 - }
988 -
989 -
990 - // -----------------------------------------------------------------------------------------------------------------
991 - // Check if existing page has our shortcode
992 - // -----------------------------------------------------------------------------------------------------------------
993 - $booking_listing_relative_url = wpbc_make_link_relative( get_bk_option( 'booking_url_bookings_listing_by_customer' ) );
994 - $is_added = wpbc_add_shortcode_to_exist_page( $booking_listing_relative_url, '[bookingcustomerlisting]' );
995 -
996 1339 }
997 1340
998 1341
999 -function wpbc_create_page_booking_payment_status(){ // FixIn: 9.6.2.13.
1000 -
1001 - global $wp_rewrite;
1342 +function wpbc_create_page_booking_payment_status(){ // FixIn: 9.6.2.13.
1343 +
1344 + if ( ! wpbc_should_create_activation_pages( 'biz_s' ) ) {
1345 + return false;
1346 + }
1347 +
1348 + global $wp_rewrite;
1002 1349 if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1.
1003 1350 return false;
1004 1351 }
1005 1352
1006 - // Successful Payment page options ---------------------------------------------------------------------------------
1007 -
1008 - $post_url_relative = false;
1009 - $slug = 'wpbc-booking-payment-successful';
1010 - if ( empty( get_page_by_path( $slug ) ) ) {
1011 - // Create page
1012 - $page_params = array(
1013 - 'post_title' => esc_html( __( 'Booking Payment Confirmation', 'booking' ) ),
1014 - 'post_content' => esc_html( __( 'Thank you for your booking. Your payment for the booking has been successfully received.', 'booking' ) ),
1015 - 'post_name' => $slug
1016 - );
1017 -
1018 - $post_id = wpbc_create_page( $page_params );
1019 -
1020 - if ( ! empty( $post_id ) ) {
1021 - $post_url = get_permalink( $post_id );
1022 - $post_url_relative = str_replace( site_url(), '', $post_url );
1023 - }
1024 - }
1025 - if ( ! empty( $post_url_relative ) ) {
1026 -
1027 - //$post_url_relative = wpbc_make_link_absolute( $post_url_relative );
1028 -
1029 - $payment_systems = array(
1030 - 'booking_stripe_v3_order_successful',
1031 - 'booking_paypal_return_url',
1032 - 'booking_authorizenet_order_successful',
1033 - 'booking_sage_order_successful',
1034 - 'booking_ideal_return_url',
1035 - 'booking_ipay88_return_url'
1036 - );
1037 -
1038 - foreach ( $payment_systems as $payment_system ) {
1039 -
1040 - if (
1041 - ( false === get_bk_option( $payment_system ) )
1042 - || ( '/successful' == wpbc_make_link_relative( get_bk_option( $payment_system ) ) )
1043 - ) {
1044 - update_bk_option( $payment_system, wpbc_make_link_relative( $post_url_relative ) );
1045 - }
1046 - }
1047 - }
1048 -
1049 - // Failed Payment page options -------------------------------------------------------------------------------------
1050 -
1051 - $post_url_relative = false;
1052 - $slug = 'wpbc-booking-payment-failed';
1053 - if ( empty( get_page_by_path( $slug ) ) ) {
1054 - // Create page
1055 - $page_params = array(
1056 - 'post_title' => esc_html( __( 'Booking Payment Failed', 'booking' ) ),
1057 - 'post_content' => esc_html( __( 'Payment Unsuccessful. Please contact us for assistance.', 'booking' ) ),
1058 - 'post_name' => $slug
1059 - );
1060 -
1061 - $post_id = wpbc_create_page( $page_params );
1062 -
1063 - if ( ! empty( $post_id ) ) {
1064 - $post_url = get_permalink( $post_id );
1065 - $post_url_relative = str_replace( site_url(), '', $post_url );
1066 - }
1067 - }
1068 - if ( ! empty( $post_url_relative ) ) {
1069 -
1070 - //$post_url_relative = wpbc_make_link_absolute( $post_url_relative );
1071 -
1072 - $payment_systems = array(
1073 - 'booking_stripe_v3_order_failed',
1074 - 'booking_paypal_cancel_return_url',
1075 - 'booking_authorizenet_order_failed',
1076 - 'booking_sage_order_failed',
1077 - 'booking_ideal_cancel_return_url',
1078 - 'booking_ipay88_cancel_return_url'
1079 - );
1080 -
1081 - foreach ( $payment_systems as $payment_system ) {
1082 -
1083 - if (
1084 - ( false === get_bk_option( $payment_system ) )
1085 - || ( '/failed' == wpbc_make_link_relative( get_bk_option( $payment_system ) ) )
1086 - ) {
1087 - update_bk_option( $payment_system, wpbc_make_link_relative( $post_url_relative ) );
1088 - }
1089 - }
1090 - }
1353 + $page_configs = wpbc_get_activation_payment_page_configs();
1354 +
1355 + foreach ( $page_configs as $page_config ) {
1356 + $existing_page = wpbc_get_activation_page_by_slugs(
1357 + $page_config['page_slug'],
1358 + $page_config['legacy_page_slugs']
1359 + );
1360 +
1361 + if ( ! ( $existing_page instanceof WP_Post ) ) {
1362 + $page_id = wpbc_create_page(
1363 + array(
1364 + 'post_title' => $page_config['page_title'],
1365 + 'post_content' => $page_config['page_content'],
1366 + 'post_name' => $page_config['page_slug'],
1367 + )
1368 + );
1369 + $existing_page = ! empty( $page_id ) ? get_post( $page_id ) : null;
1370 + }
1371 +
1372 + if ( ! ( $existing_page instanceof WP_Post ) || 'publish' !== $existing_page->post_status ) {
1373 + continue;
1374 + }
1375 +
1376 + $page_url_relative = wpbc_make_link_relative( get_permalink( $existing_page->ID ) );
1377 + if ( empty( $page_url_relative ) ) {
1378 + continue;
1379 + }
1380 +
1381 + if ( ! empty( $page_config['required_shortcode'] ) ) {
1382 + wpbc_add_shortcode_to_exist_page( $page_url_relative, $page_config['required_shortcode'] );
1383 + }
1384 +
1385 + foreach ( $page_config['option_names'] as $option_name ) {
1386 + $configured_url = get_bk_option( $option_name );
1387 +
1388 + if ( wpbc_should_update_activation_payment_url( $configured_url, $page_config['default_url'] ) ) {
1389 + update_bk_option( $option_name, $page_url_relative );
1390 + }
1391 + }
1392 + }
1091 1393 }