PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / includes / _functions / admin_menu_url.php

admin_menu_url.php in Booking Calendar 11.9, at includes/_functions/admin_menu_url.php

836 lines 32.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Admin Menu Functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email [email protected]
11 *
12 * @modified 2024-09-03
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 // =====================================================================================================================
18 // == URL functions ==
19 // =====================================================================================================================
20
21 /**
22 * Get absolute URL to relative plugin path.
23 * Possibly to load minified version of file, if its exist
24 * @param string $path - path
25 * @return string
26 */
27 function wpbc_plugin_url( $path ) {
28
29 return trailingslashit( WPBC_PLUGIN_URL ) . ltrim( $path, '/\\' );
30
31 }
32
33 // Set URL from absolute to relative (starting from /)
34 function wpbc_set_relative_url( $url ){
35
36 $url = esc_url_raw($url);
37
38 $url_path = wp_parse_url($url, PHP_URL_PATH);
39 $url_path = ( empty($url_path) ? $url : $url_path );
40
41 $url = trim($url_path, '/');
42 return '/' . $url;
43 }
44
45 /**
46 * Get Relative URL
47 *
48 * @param $maybe_absolute_link
49 *
50 * @return string
51 */
52 function wpbc_make_link_relative( $maybe_absolute_link ) {
53
54 if ( $maybe_absolute_link == get_option( 'siteurl' ) ) {
55 $maybe_absolute_link = '/';
56 }
57
58 $maybe_absolute_link = '/' . trim( wp_make_link_relative( $maybe_absolute_link ), '/' );
59
60 return $maybe_absolute_link;
61 }
62
63 /**
64 * Convert a relative front-end path to an absolute language-aware URL.
65 *
66 * The path is passed through WordPress so multilingual URL filters can apply
67 * the current language directory or domain without introducing duplicate
68 * path separators.
69 *
70 * @param string $maybe_relative_link Relative or absolute front-end URL.
71 *
72 * @return string JavaScript-safe absolute URL.
73 */
74 function wpbc_make_link_absolute( $maybe_relative_link ){
75
76 if ( ( $maybe_relative_link != home_url() ) && ( strpos( $maybe_relative_link, 'http' ) !== 0 ) ) {
77
78 $maybe_relative_link = wpbc_lang( $maybe_relative_link ); // FixIn: 8.4.5.1.
79
80 $relative_path = trim( wp_make_link_relative( $maybe_relative_link ), '/' );
81 $maybe_relative_link = home_url( '/' . $relative_path );
82 }
83
84 return esc_js( $maybe_relative_link );
85 }
86
87 /**
88 * Redirect browser to a specific page
89 *
90 * @param string $url - URL of page to redirect
91 */
92 function wpbc_redirect( $url ) {
93
94 $url = wpbc_make_link_absolute( $url );
95
96 $url = html_entity_decode( esc_url( $url ) );
97
98 echo '<script type="text/javascript">';
99 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
100 echo 'window.location.href="' . $url . '";';
101 echo '</script>';
102 echo '<noscript>';
103 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
104 echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
105 echo '</noscript>';
106 }
107
108
109 // =====================================================================================================================
110 // == Admin Menu Pages and URLs ==
111 // =====================================================================================================================
112
113 /**
114 * Check if we edit or create a new page in WordPress ?
115 * @return bool
116 */
117 function wpbc_is_on_edit_page() {
118
119 // FixIn: 9.9.0.39.
120
121 // Elementor.
122 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
123 if ( ( ! empty( $_REQUEST['action'] ) ) && ( ( 'elementor' === $_REQUEST['action'] ) || ( 'elementor_ajax' === $_REQUEST['action'] ) ) ) {
124 return false;
125 }
126
127 if ( ( ! empty( $GLOBALS['pagenow'] ) ) && ( is_admin() ) ) {
128 if (
129 ( 'post.php' === $GLOBALS['pagenow'] ) // Edit - Post / Page.
130 || ( 'post-new.php' === $GLOBALS['pagenow'] ) // Add New - Post / Page.
131 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
132 // || ( ( 'admin-ajax.php' === $GLOBALS['pagenow'] ) && ( ! empty( $_REQUEST['action'] ) ) && ( 'elementor_ajax' === $_REQUEST['action'] ) ) // Elementor Edit page - Ajax.
133 ) {
134 return true;
135 }
136 }
137
138 return false;
139 }
140
141 /**
142 * Get URL to specific Admin Menu page
143 *
144 * @param string $menu_type - { booking | add | resources | settings }
145 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
146 * @param boolean $is_old - { default: true }
147 * @return string - URL to menu
148 */
149 function wpbc_get_menu_url( $menu_type, $is_absolute_url = true, $is_old = true) {
150
151 $is_old = false;
152
153 switch ( $menu_type) {
154
155 case 'booking': // Bookings.
156 case 'bookings':
157 case 'booking-listing':
158 case 'bookings-listing':
159 case 'listing':
160 case 'overview':
161 case 'calendar-overview':
162 case 'timeline':
163 $link = 'wpbc';
164 break;
165
166 case 'add': // Add New Booking.
167 case 'add-bookings':
168 case 'add-booking':
169 case 'new':
170 case 'new-bookings':
171 case 'new-booking':
172 $link = 'wpbc&tab=add-booking';
173 break;
174
175 case 'availability':
176 $link = 'wpbc-availability';
177 break;
178
179 case 'price':
180 $link = 'wpbc-prices';
181 break;
182
183 case 'resources': // Resources.
184 case 'booking-resources':
185 $link = 'wpbc-resources';
186 break;
187
188 case 'settings': // Settings.
189 case 'options':
190 $link = 'wpbc-settings';
191 break;
192
193 case 'setup': // Setup.
194 $link = 'wpbc-setup';
195 break;
196
197 default: // Bookings.
198 $link = 'wpbc';
199 break;
200 }
201
202 if ( $is_absolute_url ) {
203 $link = admin_url( 'admin.php' ) . '?page=' . $link ;
204 }
205
206 return $link;
207 }
208
209
210 // ---------------------------------------------------------------------------------------------------------------------
211 // == URL of Admin Menu pages ==
212 // ---------------------------------------------------------------------------------------------------------------------
213
214 /**
215 * Get URL of Booking Listing or Calendar Overview page
216 *
217 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
218 * @param boolean $is_old - { default: true }
219 * @return string - URL to menu
220 */
221 function wpbc_get_bookings_url( $is_absolute_url = true, $is_old = true ) {
222 return wpbc_get_menu_url( 'booking', $is_absolute_url, $is_old );
223 }
224
225 /**
226 * Get URL of Booking > Availability page
227 *
228 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
229 * @param boolean $is_old - { default: true }
230 * @return string - URL to menu
231 */
232 function wpbc_get_availability_url( $is_absolute_url = true, $is_old = true ) {
233 return wpbc_get_menu_url( 'availability', $is_absolute_url, $is_old );
234 }
235
236 /**
237 * Get URL of Booking > Availability > General Availability page.
238 *
239 * @param boolean $is_absolute_url Absolute or relative url { default: true }.
240 * @param boolean $is_old Legacy compatibility flag.
241 *
242 * @return string URL to General Availability page.
243 */
244 function wpbc_get_general_availability_url( $is_absolute_url = true, $is_old = true ) {
245 return wpbc_get_availability_url( $is_absolute_url, $is_old ) . '&tab=general_availability';
246 }
247
248 /**
249 * Get URL of Booking > Availability > Time Slots Availability page.
250 *
251 * @param boolean $is_absolute_url Absolute or relative url { default: true }.
252 * @param boolean $is_old Legacy compatibility flag.
253 *
254 * @return string URL to Time Slots Availability page.
255 */
256 function wpbc_get_time_slots_availability_url( $is_absolute_url = true, $is_old = true ) {
257 return wpbc_get_availability_url( $is_absolute_url, $is_old ) . '&tab=time_slots_availability';
258 }
259
260 /**
261 * Get URL of Booking > Availability page
262 *
263 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
264 * @param boolean $is_old - { default: true }
265 * @return string - URL to menu
266 */
267 function wpbc_get_price_url( $is_absolute_url = true, $is_old = true ) {
268 return wpbc_get_menu_url( 'price', $is_absolute_url, $is_old );
269 }
270
271 /**
272 * Get URL of Booking > Add booking page
273 *
274 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
275 * @param boolean $is_old - { default: true }
276 * @return string - URL to menu
277 */
278 function wpbc_get_new_booking_url( $is_absolute_url = true, $is_old = true ) {
279 return wpbc_get_menu_url( 'add', $is_absolute_url, $is_old );
280 }
281
282 /**
283 * Get the normalized administrator edit-booking destination.
284 *
285 * Existing installations and malformed stored values retain the popup workflow.
286 * The optional argument keeps normalization independently testable without
287 * changing a saved WordPress option.
288 *
289 * @param null|string $stored_mode Optional stored mode. Null loads the site option.
290 *
291 * @return string Either `popup` or `add_booking_page`.
292 */
293 function wpbc_get_booking_admin_edit_mode( $stored_mode = null ) {
294
295 if ( null === $stored_mode ) {
296 $stored_mode = get_bk_option( 'booking_admin_edit_booking_mode' );
297 }
298
299 $stored_mode = sanitize_key( (string) $stored_mode );
300
301 return in_array( $stored_mode, array( 'popup', 'add_booking_page' ), true ) ? $stored_mode : 'popup';
302 }
303
304 /**
305 * Check whether administrator edit links should open the dedicated Add Booking page.
306 *
307 * @param null|string $stored_mode Optional stored mode used for independent testing.
308 *
309 * @return bool True for the dedicated page; false for the default popup.
310 */
311 function wpbc_is_booking_admin_edit_page_enabled( $stored_mode = null ) {
312 return 'add_booking_page' === wpbc_get_booking_admin_edit_mode( $stored_mode );
313 }
314
315 /**
316 * Build the authorized administrator URL for editing one Booking on Add Booking.
317 *
318 * The destination page retains its existing capability, MultiUser ownership,
319 * Booking hash, Resource, and Booking Form checks. This helper only centralizes
320 * the released URL contract used by Booking Listing and Timeline links.
321 *
322 * @param int $resource_id Booking Resource ID.
323 * @param string $booking_hash Booking edit hash.
324 * @param string $booking_form Optional custom Booking Form name.
325 *
326 * @return string Sanitized Add Booking edit URL, or an empty string when required values are missing.
327 */
328 function wpbc_get_booking_admin_edit_url( $resource_id, $booking_hash, $booking_form = '' ) {
329
330 $resource_id = absint( $resource_id );
331 $booking_hash = sanitize_text_field( (string) $booking_hash );
332 $booking_form = sanitize_text_field( (string) $booking_form );
333
334 if ( $resource_id < 1 || '' === $booking_hash ) {
335 return '';
336 }
337
338 $query_args = array(
339 'booking_type' => $resource_id,
340 'booking_hash' => $booking_hash,
341 'parent_res' => 1,
342 );
343
344 if ( '' !== $booking_form ) {
345 $query_args['booking_form'] = $booking_form;
346 }
347
348 return esc_url_raw( add_query_arg( $query_args, wpbc_get_new_booking_url( true, false ) ) );
349 }
350
351 /**
352 * Get URL of Booking > Resources page
353 *
354 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
355 * @param boolean $is_old - { default: true }
356 * @return string - URL to menu
357 */
358 function wpbc_get_resources_url( $is_absolute_url = true, $is_old = true ) {
359 return wpbc_get_menu_url( 'resources', $is_absolute_url, $is_old );
360 }
361
362 /**
363 * Get URL of Booking > Resources > Capacity page
364 *
365 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
366 * @param boolean $is_old - { default: true }
367 * @return string - URL to menu
368 */
369 function wpbc_get_resource_capacity_url( $is_absolute_url = true, $is_old = true ) {
370 return wpbc_get_resources_url( $is_absolute_url, $is_old ) . '&tab=capacity';
371 }
372
373 /**
374 * Get URL of Booking > Settings page
375 *
376 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
377 * @param boolean $is_old - { default: true }
378 * @return string - URL to menu
379 */
380 function wpbc_get_settings_url( $is_absolute_url = true, $is_old = true ) {
381 return wpbc_get_menu_url( 'settings', $is_absolute_url, $is_old );
382 }
383
384 /**
385 * Get URL of Booking > Settings > Calendar page
386 *
387 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
388 * @param boolean $is_old - { default: true }
389 * @return string - URL to menu
390 */
391 function wpbc_get_settings_calendar_url( $is_absolute_url = true, $is_old = true ) {
392 return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=calendar_settings';
393 }
394
395 /**
396 * Get URL of Booking > Settings > Appearance / Theme page
397 *
398 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
399 * @param boolean $is_old - { default: true }
400 * @return string - URL to menu
401 */
402 function wpbc_get_settings_themes_url( $is_absolute_url = true, $is_old = true ) {
403 return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=themes';
404 }
405
406 /**
407 * Get URL of Booking > Settings > Form Messages page.
408 *
409 * @param boolean $is_absolute_url Absolute or relative URL.
410 * @param boolean $is_old Legacy menu URL style.
411 * @return string
412 */
413 function wpbc_get_settings_messages_url( $is_absolute_url = true, $is_old = true ) {
414 return wpbc_get_settings_url( $is_absolute_url, $is_old ) . '&tab=form_messages';
415 }
416
417 /**
418 * Get the canonical production Setup Wizard URL.
419 *
420 * Opening this URL never restarts or completes a checkpoint. The page resumes
421 * an active checkpoint, starts Welcome when no checkpoint exists, or renders
422 * Setup overview when the checkpoint is complete. A new setup is an explicit,
423 * nonce-protected action from Setup overview.
424 *
425 * @param bool $is_absolute_url Whether to return an absolute administration URL.
426 * @param bool $is_old Retained compatibility argument; ignored by the native menu URL builder.
427 *
428 * @return string Canonical Setup Wizard URL.
429 */
430 function wpbc_get_setup_wizard_page_url( $is_absolute_url = true, $is_old = true ) {
431 return wpbc_get_menu_url( 'setup', $is_absolute_url, $is_old );
432 }
433
434
435 // -----------------------------------------------------------------------------------------------------------------
436 // == Is this specific admin page ? ==
437 // ---------------------------------------------------------------------------------------------------------------------
438
439 /**
440 * Check if this Booking Listing or Calendar Overview page
441 *
442 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
443 *
444 * @return boolean true | false
445 */
446 function wpbc_is_this_plugin_page( $server_param = 'REQUEST_URI' ) {
447
448 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
449 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc' ) !== false ) ) {
450 return true;
451 }
452
453 return false;
454 }
455
456 /**
457 * Check if this Booking Listing or Calendar Overview page
458 *
459 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
460 *
461 * @return boolean true | false
462 */
463 function wpbc_is_bookings_page( $server_param = 'REQUEST_URI' ) {
464 // Old.
465 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
466 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-reservation' ) === false ) ) {
467 return true;
468 }
469 // New.
470 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
471 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-' ) === false ) ) {
472 return true;
473 }
474
475 return false;
476 }
477
478 /**
479 * Check if this Booking > Add booking page
480 *
481 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
482 *
483 * @return boolean true | false
484 */
485 function wpbc_is_new_booking_page( $server_param = 'REQUEST_URI' ) {
486
487 if ( ! is_admin() || empty( $_SERVER[ $server_param ] ) ) {
488 return false;
489 }
490
491 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
492 if ( wpbc_is_new_booking_page_url( $_SERVER[ $server_param ] ) ) {
493 return true;
494 }
495
496 return false;
497 }
498
499 /**
500 * Check if a URL points to Booking > Bookings > Add booking.
501 *
502 * @param string $request_uri URL or request URI.
503 *
504 * @return bool
505 */
506 function wpbc_is_new_booking_page_url( $request_uri ) {
507
508 $request_uri = (string) $request_uri;
509
510 return (
511 ( false !== strpos( $request_uri, 'page=wpbc' ) )
512 && ( false === strpos( $request_uri, 'page=wpbc-' ) )
513 && ( false !== strpos( $request_uri, 'tab=add-booking' ) )
514 );
515 }
516
517 /**
518 * Check if this WP Booking Calendar > Settings > Booking Form page
519 *
520 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
521 *
522 * @return boolean true | false
523 */
524 function wpbc_is_settings_form_page( $server_param = 'REQUEST_URI' ) {
525 // Regular user overwrite settings.
526
527 // Match the legacy `form` tab exactly. A substring check also matched newer
528 // tabs whose names start with `form`, such as `form_messages`.
529 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
530 $request_uri = ! empty( $_SERVER[ $server_param ] ) ? (string) $_SERVER[ $server_param ] : '';
531 $is_form_tab = (bool) preg_match( '/(?:[?&])tab=form(?:&|$)/', $request_uri );
532
533 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
534 $is_multiuser_form_tab = class_exists( 'wpdev_bk_multiuser' ) && ! empty( $_REQUEST['tab'] ) && 'form' === $_REQUEST['tab'];
535
536 if ( is_admin() && false !== strpos( $request_uri, 'page=wpbc-settings' ) && ( $is_form_tab || $is_multiuser_form_tab ) ) {
537 return true;
538 }
539
540 return false;
541 }
542
543
544 /**
545 * Check if this WP Booking Calendar > Settings > Booking Form Builder (BFB) page.
546 *
547 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
548 *
549 * @return boolean true | false
550 */
551 function wpbc_is_settings_bfb_page( $server_param = 'REQUEST_URI' ) {
552 // Regular user overwrite settings.
553
554 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
555 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'] ) ) ) ) {
556 return true;
557 }
558
559 return false;
560 }
561
562
563 /**
564 * Check if this WP Booking Calendar > Settings > Appearance / Theme page
565 *
566 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
567 *
568 * @return boolean true | false
569 */
570 function wpbc_is_settings_themes_page( $server_param = 'REQUEST_URI' ) {
571 // Regular user overwrite settings.
572
573 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
574 if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=themes' ) ) ) {
575 return true;
576 }
577
578 return false;
579 }
580
581 /**
582 * Check if this WP Booking Calendar > Settings > Calendar page
583 *
584 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
585 *
586 * @return boolean true | false
587 */
588 function wpbc_is_settings_calendar_page( $server_param = 'REQUEST_URI' ) {
589 // Regular user overwrite settings.
590
591 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
592 if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=calendar_settings' ) ) ) {
593 return true;
594 }
595
596 return false;
597 }
598
599 /**
600 * Check if this is WP Booking Calendar > Settings > Form Messages.
601 *
602 * @param string $server_param Server URL parameter.
603 * @return boolean
604 */
605 function wpbc_is_settings_messages_page( $server_param = 'REQUEST_URI' ) {
606 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
607 return is_admin() && ! empty( $_SERVER[ $server_param ] ) && false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) && false !== strpos( $_SERVER[ $server_param ], '&tab=form_messages' );
608 }
609
610 /**
611 * Check if this admin page renders a real front-end booking form or calendar preview.
612 *
613 * @return boolean true | false
614 */
615 function wpbc_is_admin_page_with_frontend_booking_preview() {
616
617 return (
618 wpbc_is_new_booking_page()
619 || wpbc_is_settings_form_page()
620 || wpbc_is_settings_themes_page()
621 || wpbc_is_settings_calendar_page()
622 || wpbc_is_settings_messages_page()
623 || wpbc_is_setup_wizard_page()
624 || wpbc_is_builder_booking_form_page()
625 || ( function_exists( 'wpbc_add_appointment_page_is_active' ) && wpbc_add_appointment_page_is_active() )
626 || ( function_exists( 'wpbc_is_add_booking_modal_on_booking_listing_page' ) && wpbc_is_add_booking_modal_on_booking_listing_page() )
627 );
628 }
629
630 /**
631 * Check if this Booking > Availability page
632 *
633 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
634 *
635 * @return boolean true | false
636 */
637 function wpbc_is_availability_page( $server_param = 'REQUEST_URI' ) {
638
639 // New.
640 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
641 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-availability' ) !== false ) ) {
642 return true;
643 }
644
645 return false;
646 }
647
648 /**
649 * Check if this Booking > Availability page
650 *
651 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
652 *
653 * @return boolean true | false
654 */
655 function wpbc_is_builder_booking_form_page( $server_param = 'REQUEST_URI' ) {
656
657 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
658 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'tab=builder_booking_form' ) !== false ) ) {
659 return true;
660 }
661
662 return false;
663 }
664
665
666 /**
667 * Check whether the current administration URL belongs to a Booking Calendar setup route.
668 *
669 * The prefix match is intentional because the canonical route and its hidden
670 * compatibility alias share the same stable setup prefix.
671 *
672 * @param string $server_param Server field to inspect. Expected values are
673 * `REQUEST_URI` or `HTTP_REFERER`.
674 *
675 * @return bool True for any Booking Calendar setup route; otherwise false.
676 */
677 function wpbc_is_setup_wizard_page( $server_param = 'REQUEST_URI' ) { // FixIn: 9.8.0.1.
678
679 // New.
680 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
681 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-setup' ) !== false ) ) {
682 return true;
683 }
684
685 return false;
686 }
687
688 /**
689 * Check if this Booking > Resources page
690 *
691 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
692 *
693 * @return boolean true | false
694 */
695 function wpbc_is_resources_page( $server_param = 'REQUEST_URI' ) {
696
697 // Old.
698 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
699 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-resources' ) !== false ) ) {
700 return true;
701 }
702 // New.
703 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
704 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-resources' ) !== false ) ) {
705 return true;
706 }
707
708 return false;
709 }
710
711 /**
712 * Check if this Booking > Settings page
713 *
714 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
715 *
716 * @return boolean true | false
717 */
718 function wpbc_is_settings_page( $server_param = 'REQUEST_URI' ) {
719
720 // Old.
721 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
722 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-option' ) !== false ) ) {
723 return true;
724 }
725 // New.
726 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
727 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) ) {
728 return true;
729 }
730
731 return false;
732 }
733
734
735 // -----------------------------------------------------------------------------------------------------------------
736 // == support ==
737 // ---------------------------------------------------------------------------------------------------------------------
738
739 /**
740 * Transform the REQUEST parameters (GET and POST) into URL
741 *
742 * @param $page_param
743 * @param $exclude_params
744 * @param $only_these_parameters
745 * @param $is_escape_url
746 * @param $only_get
747 *
748 * @return string|null
749 */
750 function wpbc_get_params_in_url( $page_param , $exclude_params = array(), $only_these_parameters = false, $is_escape_url = true, $only_get = false ){ //FixIn: 8.0.1.101 //Fix: $is_escape_url = false
751
752 $exclude_params[] = 'page';
753 $exclude_params[] = 'post_type';
754
755 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
756 if ( isset( $_GET['page'] ) ) {
757 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
758 $page_param = $_GET['page'];
759 }
760 $get_paramaters = array( 'page' => $page_param );
761 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
762 $check_params = ( $only_get ) ? $_GET : $_REQUEST;
763
764
765 foreach ( $check_params as $prm_key => $prm_value ) {
766
767 // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 )
768 if (
769 ( is_string( $prm_value ) )
770 || ( is_numeric( $prm_value ) )
771 ){
772
773 // Check about Too long parameters, if it exists then reset it.
774 if ( strlen( $prm_value ) > 1000 ) {
775 $prm_value = '';
776 }
777
778 if ( ! in_array( $prm_key, $exclude_params ) ) {
779 if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) ) {
780 $get_paramaters[ $prm_key ] = $prm_value;
781 }
782 }
783
784 }
785 }
786
787 $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) );
788
789 if ( $is_escape_url ) {
790 $url = esc_url_raw( $url ); // FixIn: 8.1.1.7.
791 }
792
793 return $url;
794 }
795
796
797 function wpbc_left_vertival_nav__get_tab_url( $page_tag, $tab_name, $subtab_name = false, $tags = array( 'tab' => 'tab', 'subtab' => 'subtab' ) ) {
798
799 if ( false === $subtab_name ) {
800 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $tags['tab'] => $tab_name, ), 'admin.php' ) ) );
801 } else {
802 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $tags['tab'] => $tab_name, $tags['subtab'] => $subtab_name, ), 'admin.php' ) ) );
803 }
804 }
805
806 /**
807 * Get back URL for going from edit season filter or rate to specfic main page.
808 *
809 * @return string|null
810 */
811 function wpbc_get_back_button_url__for_seasons() {
812
813 $page_params_arr = array(
814 'page' => 'wpbc-availability',
815 'page_num' => 1,
816 );
817
818 if ( ! empty( $_REQUEST['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
819 $page_params_arr['page'] = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
820 }
821 if ( ! empty( $_REQUEST['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
822 $page_params_arr['tab'] = sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
823 }
824 if ( ! empty( $_REQUEST['page_num'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
825 $page_params_arr['page_num'] = intval( $_REQUEST['page_num'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
826 }
827
828 $back_url = admin_url(
829 add_query_arg(
830 $page_params_arr,
831 'admin.php'
832 )
833 );
834 return $back_url;
835 }
836