| @@ -269,14 +269,83 @@ | ||
| 269 | 269 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 270 | 270 | * @param boolean $is_old - { default: true } |
| 271 | 271 | * @return string - URL to menu |
| 272 | 272 | */ |
| 273 | -function wpbc_get_new_booking_url( $is_absolute_url = true, $is_old = true ) { | |
| 274 | - return wpbc_get_menu_url( 'add', $is_absolute_url, $is_old ); | |
| 275 | -} | |
| 276 | - | |
| 277 | -/** | |
| 278 | - * Get URL of Booking > Resources page | |
| 273 | +function wpbc_get_new_booking_url( $is_absolute_url = true, $is_old = true ) { | |
| 274 | + return wpbc_get_menu_url( 'add', $is_absolute_url, $is_old ); | |
| 275 | +} | |
| 276 | + | |
| 277 | +/** | |
| 278 | + * Get the normalized administrator edit-booking destination. | |
| 279 | + * | |
| 280 | + * Existing installations and malformed stored values retain the popup workflow. | |
| 281 | + * The optional argument keeps normalization independently testable without | |
| 282 | + * changing a saved WordPress option. | |
| 283 | + * | |
| 284 | + * @param null|string $stored_mode Optional stored mode. Null loads the site option. | |
| 285 | + * | |
| 286 | + * @return string Either `popup` or `add_booking_page`. | |
| 287 | + */ | |
| 288 | +function wpbc_get_booking_admin_edit_mode( $stored_mode = null ) { | |
| 289 | + | |
| 290 | + if ( null === $stored_mode ) { | |
| 291 | + $stored_mode = get_bk_option( 'booking_admin_edit_booking_mode' ); | |
| 292 | + } | |
| 293 | + | |
| 294 | + $stored_mode = sanitize_key( (string) $stored_mode ); | |
| 295 | + | |
| 296 | + return in_array( $stored_mode, array( 'popup', 'add_booking_page' ), true ) ? $stored_mode : 'popup'; | |
| 297 | +} | |
| 298 | + | |
| 299 | +/** | |
| 300 | + * Check whether administrator edit links should open the dedicated Add Booking page. | |
| 301 | + * | |
| 302 | + * @param null|string $stored_mode Optional stored mode used for independent testing. | |
| 303 | + * | |
| 304 | + * @return bool True for the dedicated page; false for the default popup. | |
| 305 | + */ | |
| 306 | +function wpbc_is_booking_admin_edit_page_enabled( $stored_mode = null ) { | |
| 307 | + return 'add_booking_page' === wpbc_get_booking_admin_edit_mode( $stored_mode ); | |
| 308 | +} | |
| 309 | + | |
| 310 | +/** | |
| 311 | + * Build the authorized administrator URL for editing one Booking on Add Booking. | |
| 312 | + * | |
| 313 | + * The destination page retains its existing capability, MultiUser ownership, | |
| 314 | + * Booking hash, Resource, and Booking Form checks. This helper only centralizes | |
| 315 | + * the released URL contract used by Booking Listing and Timeline links. | |
| 316 | + * | |
| 317 | + * @param int $resource_id Booking Resource ID. | |
| 318 | + * @param string $booking_hash Booking edit hash. | |
| 319 | + * @param string $booking_form Optional custom Booking Form name. | |
| 320 | + * | |
| 321 | + * @return string Sanitized Add Booking edit URL, or an empty string when required values are missing. | |
| 322 | + */ | |
| 323 | +function wpbc_get_booking_admin_edit_url( $resource_id, $booking_hash, $booking_form = '' ) { | |
| 324 | + | |
| 325 | + $resource_id = absint( $resource_id ); | |
| 326 | + $booking_hash = sanitize_text_field( (string) $booking_hash ); | |
| 327 | + $booking_form = sanitize_text_field( (string) $booking_form ); | |
| 328 | + | |
| 329 | + if ( $resource_id < 1 || '' === $booking_hash ) { | |
| 330 | + return ''; | |
| 331 | + } | |
| 332 | + | |
| 333 | + $query_args = array( | |
| 334 | + 'booking_type' => $resource_id, | |
| 335 | + 'booking_hash' => $booking_hash, | |
| 336 | + 'parent_res' => 1, | |
| 337 | + ); | |
| 338 | + | |
| 339 | + if ( '' !== $booking_form ) { | |
| 340 | + $query_args['booking_form'] = $booking_form; | |
| 341 | + } | |
| 342 | + | |
| 343 | + return esc_url_raw( add_query_arg( $query_args, wpbc_get_new_booking_url( true, false ) ) ); | |
| 344 | +} | |
| 345 | + | |
| 346 | +/** | |
| 347 | + * Get URL of Booking > Resources page | |
| 279 | 348 | * |
| 280 | 349 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 281 | 350 | * @param boolean $is_old - { default: true } |
| 282 | 351 | * @return string - URL to menu |
| @@ -539,13 +608,14 @@ | ||
| 539 | 608 | || wpbc_is_settings_form_page() |
| 540 | 609 | || wpbc_is_settings_themes_page() |
| 541 | 610 | || wpbc_is_settings_calendar_page() |
| 542 | 611 | || wpbc_is_settings_messages_page() |
| 543 | - || wpbc_is_setup_wizard_page() | |
| 544 | - || wpbc_is_builder_booking_form_page() | |
| 545 | - || ( function_exists( 'wpbc_is_add_booking_modal_on_booking_listing_page' ) && wpbc_is_add_booking_modal_on_booking_listing_page() ) | |
| 546 | - ); | |
| 547 | -} | |
| 612 | + || wpbc_is_setup_wizard_page() | |
| 613 | + || wpbc_is_builder_booking_form_page() | |
| 614 | + || ( function_exists( 'wpbc_add_appointment_page_is_active' ) && wpbc_add_appointment_page_is_active() ) | |
| 615 | + || ( function_exists( 'wpbc_is_add_booking_modal_on_booking_listing_page' ) && wpbc_is_add_booking_modal_on_booking_listing_page() ) | |
| 616 | + ); | |
| 617 | +} | |
| 548 | 618 | |
| 549 | 619 | /** |
| 550 | 620 | * Check if this Booking > Availability page |
| 551 | 621 | * |