| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @package Booking Calendar |
| @@ -163,9 +163,9 @@ | ||
| 163 | 163 | case 'add-booking': |
| 164 | 164 | case 'new': |
| 165 | 165 | case 'new-bookings': |
| 166 | 166 | case 'new-booking': |
| 167 | - $link = 'wpbc-new'; | |
| 167 | + $link = 'wpbc&tab=add-booking'; | |
| 168 | 168 | break; |
| 169 | 169 | |
| 170 | 170 | case 'availability': |
| 171 | 171 | $link = 'wpbc-availability'; |
| @@ -228,8 +228,32 @@ | ||
| 228 | 228 | return wpbc_get_menu_url( 'availability', $is_absolute_url, $is_old ); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
| 232 | + * Get URL of Booking > Availability > General Availability page. | |
| 233 | + * | |
| 234 | + * @param boolean $is_absolute_url Absolute or relative url { default: true }. | |
| 235 | + * @param boolean $is_old Legacy compatibility flag. | |
| 236 | + * | |
| 237 | + * @return string URL to General Availability page. | |
| 238 | + */ | |
| 239 | +function wpbc_get_general_availability_url( $is_absolute_url = true, $is_old = true ) { | |
| 240 | + return wpbc_get_availability_url( $is_absolute_url, $is_old ) . '&tab=general_availability'; | |
| 241 | +} | |
| 242 | + | |
| 243 | +/** | |
| 244 | + * Get URL of Booking > Availability > Time Slots Availability page. | |
| 245 | + * | |
| 246 | + * @param boolean $is_absolute_url Absolute or relative url { default: true }. | |
| 247 | + * @param boolean $is_old Legacy compatibility flag. | |
| 248 | + * | |
| 249 | + * @return string URL to Time Slots Availability page. | |
| 250 | + */ | |
| 251 | +function wpbc_get_time_slots_availability_url( $is_absolute_url = true, $is_old = true ) { | |
| 252 | + return wpbc_get_availability_url( $is_absolute_url, $is_old ) . '&tab=time_slots_availability'; | |
| 253 | +} | |
| 254 | + | |
| 255 | +/** | |
| 232 | 256 | * Get URL of Booking > Availability page |
| 233 | 257 | * |
| 234 | 258 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 235 | 259 | * @param boolean $is_old - { default: true } |
| @@ -245,21 +269,101 @@ | ||
| 245 | 269 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 246 | 270 | * @param boolean $is_old - { default: true } |
| 247 | 271 | * @return string - URL to menu |
| 248 | 272 | */ |
| 249 | -function wpbc_get_new_booking_url( $is_absolute_url = true, $is_old = true ) { | |
| 250 | - 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 ); | |
| 251 | 355 | } |
| 252 | 356 | |
| 253 | 357 | /** |
| 254 | - * Get URL of Booking > Resources page | |
| 358 | + * Get URL of Booking > Resources > Capacity page | |
| 255 | 359 | * |
| 256 | 360 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 257 | 361 | * @param boolean $is_old - { default: true } |
| 258 | 362 | * @return string - URL to menu |
| 259 | 363 | */ |
| 260 | -function wpbc_get_resources_url( $is_absolute_url = true, $is_old = true ) { | |
| 261 | - 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'; | |
| 262 | 366 | } |
| 263 | 367 | |
| 264 | 368 | /** |
| 265 | 369 | * Get URL of Booking > Settings page |
| @@ -272,8 +376,41 @@ | ||
| 272 | 376 | return wpbc_get_menu_url( 'settings', $is_absolute_url, $is_old ); |
| 273 | 377 | } |
| 274 | 378 | |
| 275 | 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 | +/** | |
| 276 | 413 | * Get URL of Booking > Setup page |
| 277 | 414 | * |
| 278 | 415 | * @param boolean $is_absolute_url - Absolute or relative url { default: true } |
| 279 | 416 | * @param boolean $is_old - { default: true } |
| @@ -334,16 +471,15 @@ | ||
| 334 | 471 | * |
| 335 | 472 | * @return boolean true | false |
| 336 | 473 | */ |
| 337 | 474 | function wpbc_is_new_booking_page( $server_param = 'REQUEST_URI' ) { |
| 338 | - // Old. | |
| 339 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 340 | - if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-reservation' ) !== false ) ) { | |
| 341 | - return true; | |
| 475 | + | |
| 476 | + if ( ! is_admin() || empty( $_SERVER[ $server_param ] ) ) { | |
| 477 | + return false; | |
| 342 | 478 | } |
| 343 | - // New. | |
| 344 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 345 | - if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-new' ) !== false ) ) { | |
| 479 | + | |
| 480 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 481 | + if ( wpbc_is_new_booking_page_url( $_SERVER[ $server_param ] ) ) { | |
| 346 | 482 | return true; |
| 347 | 483 | } |
| 348 | 484 | |
| 349 | 485 | return false; |
| @@ -349,8 +485,26 @@ | ||
| 349 | 485 | return false; |
| 350 | 486 | } |
| 351 | 487 | |
| 352 | 488 | /** |
| 489 | + * Check if a URL points to Booking > Bookings > Add booking. | |
| 490 | + * | |
| 491 | + * @param string $request_uri URL or request URI. | |
| 492 | + * | |
| 493 | + * @return bool | |
| 494 | + */ | |
| 495 | +function wpbc_is_new_booking_page_url( $request_uri ) { | |
| 496 | + | |
| 497 | + $request_uri = (string) $request_uri; | |
| 498 | + | |
| 499 | + return ( | |
| 500 | + ( false !== strpos( $request_uri, 'page=wpbc' ) ) | |
| 501 | + && ( false === strpos( $request_uri, 'page=wpbc-' ) ) | |
| 502 | + && ( false !== strpos( $request_uri, 'tab=add-booking' ) ) | |
| 503 | + ); | |
| 504 | +} | |
| 505 | + | |
| 506 | +/** | |
| 353 | 507 | * Check if this WP Booking Calendar > Settings > Booking Form page |
| 354 | 508 | * |
| 355 | 509 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 356 | 510 | * |
| @@ -355,13 +509,40 @@ | ||
| 355 | 509 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 356 | 510 | * |
| 357 | 511 | * @return boolean true | false |
| 358 | 512 | */ |
| 359 | -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' ) { | |
| 360 | 541 | // Regular user overwrite settings. |
| 361 | 542 | |
| 362 | 543 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 363 | - 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'] ) ) ) ) { | |
| 364 | 545 | return true; |
| 365 | 546 | } |
| 366 | 547 | |
| 367 | 548 | return false; |
| @@ -368,19 +549,19 @@ | ||
| 368 | 549 | } |
| 369 | 550 | |
| 370 | 551 | |
| 371 | 552 | /** |
| 372 | - * Check if this WP Booking Calendar > Settings > Booking Form Builder (BFB) page. | |
| 553 | + * Check if this WP Booking Calendar > Settings > Appearance / Theme page | |
| 373 | 554 | * |
| 374 | 555 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 375 | 556 | * |
| 376 | 557 | * @return boolean true | false |
| 377 | 558 | */ |
| 378 | -function wpbc_is_settings_bfb_page( $server_param = 'REQUEST_URI' ) { | |
| 559 | +function wpbc_is_settings_themes_page( $server_param = 'REQUEST_URI' ) { | |
| 379 | 560 | // Regular user overwrite settings. |
| 380 | 561 | |
| 381 | 562 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 382 | - 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' ) ) ) { | |
| 383 | 564 | return true; |
| 384 | 565 | } |
| 385 | 566 | |
| 386 | 567 | return false; |
| @@ -385,26 +566,56 @@ | ||
| 385 | 566 | |
| 386 | 567 | return false; |
| 387 | 568 | } |
| 388 | 569 | |
| 389 | - | |
| 390 | 570 | /** |
| 391 | - * Check if this WP Booking Calendar > Settings > Booking Form page | |
| 571 | + * Check if this WP Booking Calendar > Settings > Calendar page | |
| 392 | 572 | * |
| 393 | 573 | * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI' |
| 394 | 574 | * |
| 395 | 575 | * @return boolean true | false |
| 396 | 576 | */ |
| 397 | -function wpbc_is_settings_color_themes_page( $server_param = 'REQUEST_URI' ) { | |
| 577 | +function wpbc_is_settings_calendar_page( $server_param = 'REQUEST_URI' ) { | |
| 398 | 578 | // Regular user overwrite settings. |
| 399 | 579 | |
| 400 | 580 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 401 | - 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' ) ) ) { | |
| 402 | 582 | return true; |
| 403 | 583 | } |
| 404 | 584 | |
| 405 | 585 | return false; |
| 406 | -} | |
| 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 | +} | |
| 407 | 618 | |
| 408 | 619 | /** |
| 409 | 620 | * Check if this Booking > Availability page |
| 410 | 621 | * |