| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @package Booking Calendar |
| @@ -269,21 +269,101 @@ | ||
| 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 ); | |
| 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 | |
| 348 | + * | |
| 349 | + * @param boolean $is_absolute_url - Absolute or relative url { default: true } | |
| 350 | + * @param boolean $is_old - { default: true } | |
| 351 | + * @return string - URL to menu | |
| 352 | + */ | |
| 353 | +function wpbc_get_resources_url( $is_absolute_url = true, $is_old = true ) { | |
| 354 | + return wpbc_get_menu_url( 'resources', $is_absolute_url, $is_old ); | |
| 275 | 355 | } |
| 276 | 356 | |
| 277 | 357 | /** |
| 278 | - * Get URL of Booking > Resources page | |
| 358 | + * Get URL of Booking > Resources > Capacity page | |
| 279 | 359 | * |
| 280 | 360 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 281 | 361 | * @param boolean $is_old - { default: true } |
| 282 | 362 | * @return string - URL to menu |
| 283 | 363 | */ |
| 284 | -function wpbc_get_resources_url( $is_absolute_url = true, $is_old = true ) { | |
| 285 | - return wpbc_get_menu_url( 'resources', $is_absolute_url, $is_old ); | |
| 364 | +function wpbc_get_resource_capacity_url( $is_absolute_url = true, $is_old = true ) { | |
| 365 | + return wpbc_get_resources_url( $is_absolute_url, $is_old ) . '&tab=capacity'; | |
| 286 | 366 | } |
| 287 | 367 | |
| 288 | 368 | /** |
| 289 | 369 | * Get URL of Booking > Settings page |
| @@ -296,8 +376,41 @@ | ||
| 296 | 376 | return wpbc_get_menu_url( 'settings', $is_absolute_url, $is_old ); |
| 297 | 377 | } |
| 298 | 378 | |
| 299 | 379 | /** |
| 380 | + * Get URL of Booking > Settings > Calendar page | |
| 381 | + * | |
| 382 | + * @param boolean $is_absolute_url - Absolute or relative url { default: true } | |
| 383 | + * @param boolean $is_old - { default: true } | |
| 384 | + * @return string - URL to menu | |
| 385 | + */ | |
| 386 | +function wpbc_get_settings_calendar_url( $is_absolute_url = true, $is_old = true ) { | |
| 387 | + return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=calendar_settings'; | |
| 388 | +} | |
| 389 | + | |
| 390 | +/** | |
| 391 | + * Get URL of Booking > Settings > Appearance / Theme page | |
| 392 | + * | |
| 393 | + * @param boolean $is_absolute_url - Absolute or relative url { default: true } | |
| 394 | + * @param boolean $is_old - { default: true } | |
| 395 | + * @return string - URL to menu | |
| 396 | + */ | |
| 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 | +} | |
| 411 | + | |
| 412 | +/** | |
| 300 | 413 | * Get URL of Booking > Setup page |
| 301 | 414 | * |
| 302 | 415 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 303 | 416 | * @param boolean $is_old - { default: true } |
| @@ -396,13 +509,40 @@ | ||
| 396 | 509 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 397 | 510 | * |
| 398 | 511 | * @return boolean true | false |
| 399 | 512 | */ |
| 400 | -function wpbc_is_settings_form_page( $server_param = 'REQUEST_URI' ) { | |
| 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 | + } | |
| 528 | + | |
| 529 | + return false; | |
| 530 | +} | |
| 531 | + | |
| 532 | + | |
| 533 | +/** | |
| 534 | + * Check if this WP Booking Calendar > Settings > Booking Form Builder (BFB) page. | |
| 535 | + * | |
| 536 | + * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' | |
| 537 | + * | |
| 538 | + * @return boolean true | false | |
| 539 | + */ | |
| 540 | +function wpbc_is_settings_bfb_page( $server_param = 'REQUEST_URI' ) { | |
| 401 | 541 | // Regular user overwrite settings. |
| 402 | 542 | |
| 403 | 543 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 404 | - 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'] ) ) ) ) { | |
| 544 | + if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) && ( ( strpos( $_SERVER[ $server_param ], '&tab=builder_booking_form' ) !== false ) || ( ( class_exists( 'wpdev_bk_multiuser' ) ) && ( ! empty( $_REQUEST['tab'] ) ) && ( 'builder_booking_form' === $_REQUEST['tab'] ) ) ) ) { | |
| 405 | 545 | return true; |
| 406 | 546 | } |
| 407 | 547 | |
| 408 | 548 | return false; |
| @@ -409,19 +549,19 @@ | ||
| 409 | 549 | } |
| 410 | 550 | |
| 411 | 551 | |
| 412 | 552 | /** |
| 413 | - * Check if this WP Booking Calendar > Settings > Booking Form Builder (BFB) page. | |
| 553 | + * Check if this WP Booking Calendar > Settings > Appearance / Theme page | |
| 414 | 554 | * |
| 415 | 555 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 416 | 556 | * |
| 417 | 557 | * @return boolean true | false |
| 418 | 558 | */ |
| 419 | -function wpbc_is_settings_bfb_page( $server_param = 'REQUEST_URI' ) { | |
| 559 | +function wpbc_is_settings_themes_page( $server_param = 'REQUEST_URI' ) { | |
| 420 | 560 | // Regular user overwrite settings. |
| 421 | 561 | |
| 422 | 562 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 423 | - if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) && ( ( strpos( $_SERVER[ $server_param ], '&tab=builder_booking_form' ) !== false ) || ( ( class_exists( 'wpdev_bk_multiuser' ) ) && ( ! empty( $_REQUEST['tab'] ) ) && ( 'builder_booking_form' === $_REQUEST['tab'] ) ) ) ) { | |
| 563 | + if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=themes' ) ) ) { | |
| 424 | 564 | return true; |
| 425 | 565 | } |
| 426 | 566 | |
| 427 | 567 | return false; |
| @@ -426,26 +566,56 @@ | ||
| 426 | 566 | |
| 427 | 567 | return false; |
| 428 | 568 | } |
| 429 | 569 | |
| 430 | - | |
| 431 | 570 | /** |
| 432 | - * Check if this WP Booking Calendar > Settings > Booking Form page | |
| 571 | + * Check if this WP Booking Calendar > Settings > Calendar page | |
| 433 | 572 | * |
| 434 | 573 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 435 | 574 | * |
| 436 | 575 | * @return boolean true | false |
| 437 | 576 | */ |
| 438 | -function wpbc_is_settings_color_themes_page( $server_param = 'REQUEST_URI' ) { | |
| 577 | +function wpbc_is_settings_calendar_page( $server_param = 'REQUEST_URI' ) { | |
| 439 | 578 | // Regular user overwrite settings. |
| 440 | 579 | |
| 441 | 580 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 442 | - if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=color_themes' ) ) ) { | |
| 581 | + if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=calendar_settings' ) ) ) { | |
| 443 | 582 | return true; |
| 444 | 583 | } |
| 445 | 584 | |
| 446 | 585 | return false; |
| 447 | -} | |
| 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 | +} | |
| 598 | + | |
| 599 | +/** | |
| 600 | + * Check if this admin page renders a real front-end booking form or calendar preview. | |
| 601 | + * | |
| 602 | + * @return boolean true | false | |
| 603 | + */ | |
| 604 | +function wpbc_is_admin_page_with_frontend_booking_preview() { | |
| 605 | + | |
| 606 | + return ( | |
| 607 | + wpbc_is_new_booking_page() | |
| 608 | + || wpbc_is_settings_form_page() | |
| 609 | + || wpbc_is_settings_themes_page() | |
| 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 | +} | |
| 448 | 618 | |
| 449 | 619 | /** |
| 450 | 620 | * Check if this Booking > Availability page |
| 451 | 621 | * |