| @@ -68,82 +68,8 @@ | ||
| 68 | 68 | return $setup_choices; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Resolve the administration mode associated with a Setup Wizard booking type. | |
| 73 | - * | |
| 74 | - * The Setup Wizard remains authoritative for booking-form and availability | |
| 75 | - * configuration. This mapping changes only the owner-scoped administration | |
| 76 | - * presentation selected after that configuration is saved. | |
| 77 | - * | |
| 78 | - * @param string $booking_type Sanitized Setup Wizard booking type identifier. | |
| 79 | - * @param string $requested_mode_id Optional explicit mode selected in Step 4. | |
| 80 | - * | |
| 81 | - * @return string Allowed Booking Modes identifier, or an empty string when the | |
| 82 | - * booking type must not change the current selection. | |
| 83 | - */ | |
| 84 | -function wpbc_booking_modes_get_setup_mode_id( $booking_type, $requested_mode_id = '' ) { | |
| 85 | - | |
| 86 | - $booking_type = is_scalar( $booking_type ) ? sanitize_key( (string) $booking_type ) : ''; | |
| 87 | - $requested_mode_id = is_scalar( $requested_mode_id ) ? sanitize_key( (string) $requested_mode_id ) : ''; | |
| 88 | - | |
| 89 | - if ( '' !== $requested_mode_id ) { | |
| 90 | - return in_array( $requested_mode_id, wpbc_booking_modes_get_allowed_mode_ids(), true ) ? $requested_mode_id : ''; | |
| 91 | - } | |
| 92 | - | |
| 93 | - $mode_map = array( | |
| 94 | - 'full_days_bookings' => 'rental', | |
| 95 | - 'time_slots_appointments' => 'appointment', | |
| 96 | - 'changeover_multi_dates_bookings' => 'rental', | |
| 97 | - ); | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * Filter the Setup Wizard booking-type to administration-mode mapping. | |
| 101 | - * | |
| 102 | - * @param array $mode_map Mode identifiers keyed by Setup Wizard booking type. | |
| 103 | - * @param string $booking_type Sanitized booking type currently being resolved. | |
| 104 | - */ | |
| 105 | - $mode_map = apply_filters( 'wpbc_booking_modes_setup_booking_type_map', $mode_map, $booking_type ); | |
| 106 | - | |
| 107 | - if ( ! is_array( $mode_map ) || ! isset( $mode_map[ $booking_type ] ) ) { | |
| 108 | - return ''; | |
| 109 | - } | |
| 110 | - | |
| 111 | - $mode_id = is_scalar( $mode_map[ $booking_type ] ) ? sanitize_key( (string) $mode_map[ $booking_type ] ) : ''; | |
| 112 | - | |
| 113 | - return in_array( $mode_id, wpbc_booking_modes_get_allowed_mode_ids(), true ) ? $mode_id : ''; | |
| 114 | -} | |
| 115 | - | |
| 116 | -/** | |
| 117 | - * Persist the presentation mode selected indirectly by the Setup Wizard. | |
| 118 | - * | |
| 119 | - * This handler runs only after the wizard has validated, applied, and stored | |
| 120 | - * its booking-type configuration. It deliberately does not run QuickStart or | |
| 121 | - * mutate bookings, resources, Services, pages, availability, or prices. | |
| 122 | - * | |
| 123 | - * @param array $cleaned_data Validated Setup Wizard booking-type data. | |
| 124 | - * | |
| 125 | - * @return bool|WP_Error True when saved, false when no mapping applies, or a | |
| 126 | - * storage error returned by the Booking Modes API. | |
| 127 | - */ | |
| 128 | -function wpbc_booking_modes_apply_setup_booking_type( $cleaned_data ) { | |
| 129 | - | |
| 130 | - if ( ! is_array( $cleaned_data ) || empty( $cleaned_data['wpbc_swp_booking_types'] ) ) { | |
| 131 | - return false; | |
| 132 | - } | |
| 133 | - | |
| 134 | - $requested_mode_id = isset( $cleaned_data['wpbc_swp_booking_mode'] ) ? $cleaned_data['wpbc_swp_booking_mode'] : ''; | |
| 135 | - $mode_id = wpbc_booking_modes_get_setup_mode_id( $cleaned_data['wpbc_swp_booking_types'], $requested_mode_id ); | |
| 136 | - | |
| 137 | - if ( '' === $mode_id ) { | |
| 138 | - return false; | |
| 139 | - } | |
| 140 | - | |
| 141 | - return wpbc_booking_modes_set_selected_mode_id( $mode_id ); | |
| 142 | -} | |
| 143 | -add_action( 'wpbc_setup_wizard_booking_type_saved', 'wpbc_booking_modes_apply_setup_booking_type' ); | |
| 144 | - | |
| 145 | -/** | |
| 146 | 72 | * Add one published page to a Setup Wizard test-link collection. |
| 147 | 73 | * |
| 148 | 74 | * @param array $page_links Page-link collection passed by reference. |
| 149 | 75 | * @param string $page_url Public page URL. |