| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @package Booking Calendar |
| @@ -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 |
| @@ -324,11 +393,22 @@ | ||
| 324 | 393 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 325 | 394 | * @param boolean $is_old - { default: true } |
| 326 | 395 | * @return string - URL to menu |
| 327 | 396 | */ |
| 328 | -function wpbc_get_settings_themes_url( $is_absolute_url = true, $is_old = true ) { | |
| 329 | - return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=themes'; | |
| 330 | -} | |
| 397 | +function wpbc_get_settings_themes_url( $is_absolute_url = true, $is_old = true ) { | |
| 398 | + return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=themes'; | |
| 399 | +} | |
| 400 | + | |
| 401 | +/** | |
| 402 | + * Get URL of Booking > Settings > Form Messages page. | |
| 403 | + * | |
| 404 | + * @param boolean $is_absolute_url Absolute or relative URL. | |
| 405 | + * @param boolean $is_old Legacy menu URL style. | |
| 406 | + * @return string | |
| 407 | + */ | |
| 408 | +function wpbc_get_settings_messages_url( $is_absolute_url = true, $is_old = true ) { | |
| 409 | + return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=form_messages'; | |
| 410 | +} | |
| 331 | 411 | |
| 332 | 412 | /** |
| 333 | 413 | * Get URL of Booking > Setup page |
| 334 | 414 | * |
| @@ -429,16 +509,24 @@ | ||
| 429 | 509 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 430 | 510 | * |
| 431 | 511 | * @return boolean true | false |
| 432 | 512 | */ |
| 433 | -function wpbc_is_settings_form_page( $server_param = 'REQUEST_URI' ) { | |
| 434 | - // Regular user overwrite settings. | |
| 513 | +function wpbc_is_settings_form_page( $server_param = 'REQUEST_URI' ) { | |
| 514 | + // Regular user overwrite settings. | |
| 515 | + | |
| 516 | + // Match the legacy `form` tab exactly. A substring check also matched newer | |
| 517 | + // tabs whose names start with `form`, such as `form_messages`. | |
| 518 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 519 | + $request_uri = ! empty( $_SERVER[ $server_param ] ) ? (string) $_SERVER[ $server_param ] : ''; | |
| 520 | + $is_form_tab = (bool) preg_match( '/(?:[?&])tab=form(?:&|$)/', $request_uri ); | |
| 521 | + | |
| 522 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 523 | + $is_multiuser_form_tab = class_exists( 'wpdev_bk_multiuser' ) && ! empty( $_REQUEST['tab'] ) && 'form' === $_REQUEST['tab']; | |
| 524 | + | |
| 525 | + if ( is_admin() && false !== strpos( $request_uri, 'page=wpbc-settings' ) && ( $is_form_tab || $is_multiuser_form_tab ) ) { | |
| 526 | + return true; | |
| 527 | + } | |
| 435 | 528 | |
| 436 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 437 | - if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) && ( ( strpos( $_SERVER[ $server_param ], '&tab=form' ) !== false ) || ( ( class_exists( 'wpdev_bk_multiuser' ) ) && ( ! empty( $_REQUEST['tab'] ) ) && ( 'form' === $_REQUEST['tab'] ) ) ) ) { | |
| 438 | - return true; | |
| 439 | - } | |
| 440 | - | |
| 441 | 529 | return false; |
| 442 | 530 | } |
| 443 | 531 | |
| 444 | 532 | |
| @@ -485,9 +573,9 @@ | ||
| 485 | 573 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 486 | 574 | * |
| 487 | 575 | * @return boolean true | false |
| 488 | 576 | */ |
| 489 | -function wpbc_is_settings_calendar_page( $server_param = 'REQUEST_URI' ) { | |
| 577 | +function wpbc_is_settings_calendar_page( $server_param = 'REQUEST_URI' ) { | |
| 490 | 578 | // Regular user overwrite settings. |
| 491 | 579 | |
| 492 | 580 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 493 | 581 | if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=calendar_settings' ) ) ) { |
| @@ -494,9 +582,20 @@ | ||
| 494 | 582 | return true; |
| 495 | 583 | } |
| 496 | 584 | |
| 497 | 585 | return false; |
| 498 | -} | |
| 586 | +} | |
| 587 | + | |
| 588 | +/** | |
| 589 | + * Check if this is WP Booking Calendar > Settings > Form Messages. | |
| 590 | + * | |
| 591 | + * @param string $server_param Server URL parameter. | |
| 592 | + * @return boolean | |
| 593 | + */ | |
| 594 | +function wpbc_is_settings_messages_page( $server_param = 'REQUEST_URI' ) { | |
| 595 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 596 | + return is_admin() && ! empty( $_SERVER[ $server_param ] ) && false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) && false !== strpos( $_SERVER[ $server_param ], '&tab=form_messages' ); | |
| 597 | +} | |
| 499 | 598 | |
| 500 | 599 | /** |
| 501 | 600 | * Check if this admin page renders a real front-end booking form or calendar preview. |
| 502 | 601 | * |
| @@ -507,14 +606,16 @@ | ||
| 507 | 606 | return ( |
| 508 | 607 | wpbc_is_new_booking_page() |
| 509 | 608 | || wpbc_is_settings_form_page() |
| 510 | 609 | || wpbc_is_settings_themes_page() |
| 511 | - || wpbc_is_settings_calendar_page() | |
| 512 | - || wpbc_is_setup_wizard_page() | |
| 513 | - || wpbc_is_builder_booking_form_page() | |
| 514 | - || ( function_exists( 'wpbc_is_add_booking_modal_on_booking_listing_page' ) && wpbc_is_add_booking_modal_on_booking_listing_page() ) | |
| 515 | - ); | |
| 516 | -} | |
| 610 | + || wpbc_is_settings_calendar_page() | |
| 611 | + || wpbc_is_settings_messages_page() | |
| 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 | +} | |
| 517 | 618 | |
| 518 | 619 | /** |
| 519 | 620 | * Check if this Booking > Availability page |
| 520 | 621 | * |