PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
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 10.11 10.11.2 10.11.3 10.11.4 All 201 releases
booking / includes / _functions / admin_menu_url.php

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

821 lines 31.2 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 info@wpbookingcalendar.com
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 * Get Absolute URL (check for languages)
65 *
66 * @param $maybe_relative_link
67 *
68 * @return string
69 */
70 function wpbc_make_link_absolute( $maybe_relative_link ){
71
72 if ( ( $maybe_relative_link != home_url() ) && ( strpos( $maybe_relative_link, 'http' ) !== 0 ) ) {
73
74 $maybe_relative_link = wpbc_lang( $maybe_relative_link ); // FixIn: 8.4.5.1.
75
76 $maybe_relative_link = home_url() . '/' . trim( wp_make_link_relative( $maybe_relative_link ), '/' ); // FixIn: 7.0.1.20.
77 }
78
79 return esc_js( $maybe_relative_link );
80 }
81
82 /**
83 * Redirect browser to a specific page
84 *
85 * @param string $url - URL of page to redirect
86 */
87 function wpbc_redirect( $url ) {
88
89 $url = wpbc_make_link_absolute( $url );
90
91 $url = html_entity_decode( esc_url( $url ) );
92
93 echo '<script type="text/javascript">';
94 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
95 echo 'window.location.href="' . $url . '";';
96 echo '</script>';
97 echo '<noscript>';
98 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
99 echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
100 echo '</noscript>';
101 }
102
103
104 // =====================================================================================================================
105 // == Admin Menu Pages and URLs ==
106 // =====================================================================================================================
107
108 /**
109 * Check if we edit or create a new page in WordPress ?
110 * @return bool
111 */
112 function wpbc_is_on_edit_page() {
113
114 // FixIn: 9.9.0.39.
115
116 // Elementor.
117 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
118 if ( ( ! empty( $_REQUEST['action'] ) ) && ( ( 'elementor' === $_REQUEST['action'] ) || ( 'elementor_ajax' === $_REQUEST['action'] ) ) ) {
119 return false;
120 }
121
122 if ( ( ! empty( $GLOBALS['pagenow'] ) ) && ( is_admin() ) ) {
123 if (
124 ( 'post.php' === $GLOBALS['pagenow'] ) // Edit - Post / Page.
125 || ( 'post-new.php' === $GLOBALS['pagenow'] ) // Add New - Post / Page.
126 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
127 // || ( ( 'admin-ajax.php' === $GLOBALS['pagenow'] ) && ( ! empty( $_REQUEST['action'] ) ) && ( 'elementor_ajax' === $_REQUEST['action'] ) ) // Elementor Edit page - Ajax.
128 ) {
129 return true;
130 }
131 }
132
133 return false;
134 }
135
136 /**
137 * Get URL to specific Admin Menu page
138 *
139 * @param string $menu_type - { booking | add | resources | settings }
140 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
141 * @param boolean $is_old - { default: true }
142 * @return string - URL to menu
143 */
144 function wpbc_get_menu_url( $menu_type, $is_absolute_url = true, $is_old = true) {
145
146 $is_old = false;
147
148 switch ( $menu_type) {
149
150 case 'booking': // Bookings.
151 case 'bookings':
152 case 'booking-listing':
153 case 'bookings-listing':
154 case 'listing':
155 case 'overview':
156 case 'calendar-overview':
157 case 'timeline':
158 $link = 'wpbc';
159 break;
160
161 case 'add': // Add New Booking.
162 case 'add-bookings':
163 case 'add-booking':
164 case 'new':
165 case 'new-bookings':
166 case 'new-booking':
167 $link = 'wpbc&tab=add-booking';
168 break;
169
170 case 'availability':
171 $link = 'wpbc-availability';
172 break;
173
174 case 'price':
175 $link = 'wpbc-prices';
176 break;
177
178 case 'resources': // Resources.
179 case 'booking-resources':
180 $link = 'wpbc-resources';
181 break;
182
183 case 'settings': // Settings.
184 case 'options':
185 $link = 'wpbc-settings';
186 break;
187
188 case 'setup': // Setup.
189 $link = 'wpbc-setup';
190 break;
191
192 default: // Bookings.
193 $link = 'wpbc';
194 break;
195 }
196
197 if ( $is_absolute_url ) {
198 $link = admin_url( 'admin.php' ) . '?page=' . $link ;
199 }
200
201 return $link;
202 }
203
204
205 // ---------------------------------------------------------------------------------------------------------------------
206 // == URL of Admin Menu pages ==
207 // ---------------------------------------------------------------------------------------------------------------------
208
209 /**
210 * Get URL of Booking Listing or Calendar Overview page
211 *
212 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
213 * @param boolean $is_old - { default: true }
214 * @return string - URL to menu
215 */
216 function wpbc_get_bookings_url( $is_absolute_url = true, $is_old = true ) {
217 return wpbc_get_menu_url( 'booking', $is_absolute_url, $is_old );
218 }
219
220 /**
221 * Get URL of Booking > Availability page
222 *
223 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
224 * @param boolean $is_old - { default: true }
225 * @return string - URL to menu
226 */
227 function wpbc_get_availability_url( $is_absolute_url = true, $is_old = true ) {
228 return wpbc_get_menu_url( 'availability', $is_absolute_url, $is_old );
229 }
230
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 /**
256 * Get URL of Booking > Availability page
257 *
258 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
259 * @param boolean $is_old - { default: true }
260 * @return string - URL to menu
261 */
262 function wpbc_get_price_url( $is_absolute_url = true, $is_old = true ) {
263 return wpbc_get_menu_url( 'price', $is_absolute_url, $is_old );
264 }
265
266 /**
267 * Get URL of Booking > Add booking page
268 *
269 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
270 * @param boolean $is_old - { default: true }
271 * @return string - URL to menu
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 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 );
355 }
356
357 /**
358 * Get URL of Booking > Resources > Capacity page
359 *
360 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
361 * @param boolean $is_old - { default: true }
362 * @return string - URL to menu
363 */
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';
366 }
367
368 /**
369 * Get URL of Booking > Settings page
370 *
371 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
372 * @param boolean $is_old - { default: true }
373 * @return string - URL to menu
374 */
375 function wpbc_get_settings_url( $is_absolute_url = true, $is_old = true ) {
376 return wpbc_get_menu_url( 'settings', $is_absolute_url, $is_old );
377 }
378
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 /**
413 * Get URL of Booking > Setup page
414 *
415 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
416 * @param boolean $is_old - { default: true }
417 * @return string - URL to menu
418 */
419 function wpbc_get_setup_wizard_page_url( $is_absolute_url = true, $is_old = true ) {
420 return wpbc_get_menu_url( 'setup', $is_absolute_url, $is_old );
421 }
422
423
424 // -----------------------------------------------------------------------------------------------------------------
425 // == Is this specific admin page ? ==
426 // ---------------------------------------------------------------------------------------------------------------------
427
428 /**
429 * Check if this Booking Listing or Calendar Overview page
430 *
431 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
432 *
433 * @return boolean true | false
434 */
435 function wpbc_is_this_plugin_page( $server_param = 'REQUEST_URI' ) {
436
437 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
438 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc' ) !== false ) ) {
439 return true;
440 }
441
442 return false;
443 }
444
445 /**
446 * Check if this Booking Listing or Calendar Overview page
447 *
448 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
449 *
450 * @return boolean true | false
451 */
452 function wpbc_is_bookings_page( $server_param = 'REQUEST_URI' ) {
453 // Old.
454 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
455 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-reservation' ) === false ) ) {
456 return true;
457 }
458 // New.
459 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
460 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-' ) === false ) ) {
461 return true;
462 }
463
464 return false;
465 }
466
467 /**
468 * Check if this Booking > Add booking page
469 *
470 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
471 *
472 * @return boolean true | false
473 */
474 function wpbc_is_new_booking_page( $server_param = 'REQUEST_URI' ) {
475
476 if ( ! is_admin() || empty( $_SERVER[ $server_param ] ) ) {
477 return false;
478 }
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 ] ) ) {
482 return true;
483 }
484
485 return false;
486 }
487
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 /**
507 * Check if this WP Booking Calendar > Settings > Booking Form page
508 *
509 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
510 *
511 * @return boolean true | false
512 */
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' ) {
541 // Regular user overwrite settings.
542
543 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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'] ) ) ) ) {
545 return true;
546 }
547
548 return false;
549 }
550
551
552 /**
553 * Check if this WP Booking Calendar > Settings > Appearance / Theme page
554 *
555 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
556 *
557 * @return boolean true | false
558 */
559 function wpbc_is_settings_themes_page( $server_param = 'REQUEST_URI' ) {
560 // Regular user overwrite settings.
561
562 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
563 if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=themes' ) ) ) {
564 return true;
565 }
566
567 return false;
568 }
569
570 /**
571 * Check if this WP Booking Calendar > Settings > Calendar page
572 *
573 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
574 *
575 * @return boolean true | false
576 */
577 function wpbc_is_settings_calendar_page( $server_param = 'REQUEST_URI' ) {
578 // Regular user overwrite settings.
579
580 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
581 if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=calendar_settings' ) ) ) {
582 return true;
583 }
584
585 return false;
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 }
618
619 /**
620 * Check if this Booking > Availability page
621 *
622 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
623 *
624 * @return boolean true | false
625 */
626 function wpbc_is_availability_page( $server_param = 'REQUEST_URI' ) {
627
628 // New.
629 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
630 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-availability' ) !== false ) ) {
631 return true;
632 }
633
634 return false;
635 }
636
637 /**
638 * Check if this Booking > Availability page
639 *
640 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
641 *
642 * @return boolean true | false
643 */
644 function wpbc_is_builder_booking_form_page( $server_param = 'REQUEST_URI' ) {
645
646 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
647 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'tab=builder_booking_form' ) !== false ) ) {
648 return true;
649 }
650
651 return false;
652 }
653
654
655 /**
656 * Check if this Booking > Setup page
657 *
658 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
659 *
660 * @return boolean true | false
661 */
662 function wpbc_is_setup_wizard_page( $server_param = 'REQUEST_URI' ) { // FixIn: 9.8.0.1.
663
664 // New.
665 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
666 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-setup' ) !== false ) ) {
667 return true;
668 }
669
670 return false;
671 }
672
673 /**
674 * Check if this Booking > Resources page
675 *
676 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
677 *
678 * @return boolean true | false
679 */
680 function wpbc_is_resources_page( $server_param = 'REQUEST_URI' ) {
681
682 // Old.
683 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
684 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-resources' ) !== false ) ) {
685 return true;
686 }
687 // New.
688 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
689 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-resources' ) !== false ) ) {
690 return true;
691 }
692
693 return false;
694 }
695
696 /**
697 * Check if this Booking > Settings page
698 *
699 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
700 *
701 * @return boolean true | false
702 */
703 function wpbc_is_settings_page( $server_param = 'REQUEST_URI' ) {
704
705 // Old.
706 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
707 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-option' ) !== false ) ) {
708 return true;
709 }
710 // New.
711 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
712 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) ) {
713 return true;
714 }
715
716 return false;
717 }
718
719
720 // -----------------------------------------------------------------------------------------------------------------
721 // == support ==
722 // ---------------------------------------------------------------------------------------------------------------------
723
724 /**
725 * Transform the REQUEST parameters (GET and POST) into URL
726 *
727 * @param $page_param
728 * @param $exclude_params
729 * @param $only_these_parameters
730 * @param $is_escape_url
731 * @param $only_get
732 *
733 * @return string|null
734 */
735 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
736
737 $exclude_params[] = 'page';
738 $exclude_params[] = 'post_type';
739
740 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
741 if ( isset( $_GET['page'] ) ) {
742 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
743 $page_param = $_GET['page'];
744 }
745 $get_paramaters = array( 'page' => $page_param );
746 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
747 $check_params = ( $only_get ) ? $_GET : $_REQUEST;
748
749
750 foreach ( $check_params as $prm_key => $prm_value ) {
751
752 // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 )
753 if (
754 ( is_string( $prm_value ) )
755 || ( is_numeric( $prm_value ) )
756 ){
757
758 // Check about Too long parameters, if it exists then reset it.
759 if ( strlen( $prm_value ) > 1000 ) {
760 $prm_value = '';
761 }
762
763 if ( ! in_array( $prm_key, $exclude_params ) ) {
764 if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) ) {
765 $get_paramaters[ $prm_key ] = $prm_value;
766 }
767 }
768
769 }
770 }
771
772 $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) );
773
774 if ( $is_escape_url ) {
775 $url = esc_url_raw( $url ); // FixIn: 8.1.1.7.
776 }
777
778 return $url;
779 }
780
781
782 function wpbc_left_vertival_nav__get_tab_url( $page_tag, $tab_name, $subtab_name = false, $tags = array( 'tab' => 'tab', 'subtab' => 'subtab' ) ) {
783
784 if ( false === $subtab_name ) {
785 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $tags['tab'] => $tab_name, ), 'admin.php' ) ) );
786 } else {
787 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $tags['tab'] => $tab_name, $tags['subtab'] => $subtab_name, ), 'admin.php' ) ) );
788 }
789 }
790
791 /**
792 * Get back URL for going from edit season filter or rate to specfic main page.
793 *
794 * @return string|null
795 */
796 function wpbc_get_back_button_url__for_seasons() {
797
798 $page_params_arr = array(
799 'page' => 'wpbc-availability',
800 'page_num' => 1,
801 );
802
803 if ( ! empty( $_REQUEST['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
804 $page_params_arr['page'] = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
805 }
806 if ( ! empty( $_REQUEST['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
807 $page_params_arr['tab'] = sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
808 }
809 if ( ! empty( $_REQUEST['page_num'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
810 $page_params_arr['page_num'] = intval( $_REQUEST['page_num'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
811 }
812
813 $back_url = admin_url(
814 add_query_arg(
815 $page_params_arr,
816 'admin.php'
817 )
818 );
819 return $back_url;
820 }
821