PluginProbe
Booking Calendar / 10.11
Booking Calendar v10.11
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 10.11 10.11.2 All 203 releases
booking / includes / _functions / admin_menu_url.php

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

551 lines 21.0 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 if ( ( ! empty( $GLOBALS['pagenow'] ) ) && ( is_admin() ) ) {
117 if (
118 ( 'post.php' === $GLOBALS['pagenow'] ) // Edit - Post / Page.
119 || ( 'post-new.php' === $GLOBALS['pagenow'] ) // Add New - Post / Page.
120 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
121 || ( ( 'admin-ajax.php' === $GLOBALS['pagenow'] ) && ( ! empty( $_REQUEST['action'] ) ) && ( 'elementor_ajax' === $_REQUEST['action'] ) ) // Elementor Edit page - Ajax.
122 ) {
123 return true;
124 }
125 }
126
127 return false;
128 }
129
130 /**
131 * Get URL to specific Admin Menu page
132 *
133 * @param string $menu_type - { booking | add | resources | settings }
134 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
135 * @param boolean $is_old - { default: true }
136 * @return string - URL to menu
137 */
138 function wpbc_get_menu_url( $menu_type, $is_absolute_url = true, $is_old = true) {
139
140 $is_old = false;
141
142 switch ( $menu_type) {
143
144 case 'booking': // Bookings.
145 case 'bookings':
146 case 'booking-listing':
147 case 'bookings-listing':
148 case 'listing':
149 case 'overview':
150 case 'calendar-overview':
151 case 'timeline':
152 $link = 'wpbc';
153 break;
154
155 case 'add': // Add New Booking.
156 case 'add-bookings':
157 case 'add-booking':
158 case 'new':
159 case 'new-bookings':
160 case 'new-booking':
161 $link = 'wpbc-new';
162 break;
163
164 case 'availability':
165 $link = 'wpbc-availability';
166 break;
167
168 case 'price':
169 $link = 'wpbc-prices';
170 break;
171
172 case 'resources': // Resources.
173 case 'booking-resources':
174 $link = 'wpbc-resources';
175 break;
176
177 case 'settings': // Settings.
178 case 'options':
179 $link = 'wpbc-settings';
180 break;
181
182 case 'setup': // Setup.
183 $link = 'wpbc-setup';
184 break;
185
186 default: // Bookings.
187 $link = 'wpbc';
188 break;
189 }
190
191 if ( $is_absolute_url ) {
192 $link = admin_url( 'admin.php' ) . '?page=' . $link ;
193 }
194
195 return $link;
196 }
197
198
199 // ---------------------------------------------------------------------------------------------------------------------
200 // == URL of Admin Menu pages ==
201 // ---------------------------------------------------------------------------------------------------------------------
202
203 /**
204 * Get URL of Booking Listing or Calendar Overview page
205 *
206 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
207 * @param boolean $is_old - { default: true }
208 * @return string - URL to menu
209 */
210 function wpbc_get_bookings_url( $is_absolute_url = true, $is_old = true ) {
211 return wpbc_get_menu_url( 'booking', $is_absolute_url, $is_old );
212 }
213
214 /**
215 * Get URL of Booking > Availability 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_availability_url( $is_absolute_url = true, $is_old = true ) {
222 return wpbc_get_menu_url( 'availability', $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_price_url( $is_absolute_url = true, $is_old = true ) {
233 return wpbc_get_menu_url( 'price', $is_absolute_url, $is_old );
234 }
235
236 /**
237 * Get URL of Booking > Add booking page
238 *
239 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
240 * @param boolean $is_old - { default: true }
241 * @return string - URL to menu
242 */
243 function wpbc_get_new_booking_url( $is_absolute_url = true, $is_old = true ) {
244 return wpbc_get_menu_url( 'add', $is_absolute_url, $is_old );
245 }
246
247 /**
248 * Get URL of Booking > Resources page
249 *
250 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
251 * @param boolean $is_old - { default: true }
252 * @return string - URL to menu
253 */
254 function wpbc_get_resources_url( $is_absolute_url = true, $is_old = true ) {
255 return wpbc_get_menu_url( 'resources', $is_absolute_url, $is_old );
256 }
257
258 /**
259 * Get URL of Booking > Settings page
260 *
261 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
262 * @param boolean $is_old - { default: true }
263 * @return string - URL to menu
264 */
265 function wpbc_get_settings_url( $is_absolute_url = true, $is_old = true ) {
266 return wpbc_get_menu_url( 'settings', $is_absolute_url, $is_old );
267 }
268
269 /**
270 * Get URL of Booking > Setup page
271 *
272 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
273 * @param boolean $is_old - { default: true }
274 * @return string - URL to menu
275 */
276 function wpbc_get_setup_wizard_page_url( $is_absolute_url = true, $is_old = true ) {
277 return wpbc_get_menu_url( 'setup', $is_absolute_url, $is_old );
278 }
279
280
281 // -----------------------------------------------------------------------------------------------------------------
282 // == Is this specific admin page ? ==
283 // ---------------------------------------------------------------------------------------------------------------------
284
285 /**
286 * Check if this Booking Listing or Calendar Overview page
287 *
288 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
289 *
290 * @return boolean true | false
291 */
292 function wpbc_is_bookings_page( $server_param = 'REQUEST_URI' ) {
293 // Old.
294 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
295 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-reservation' ) === false ) ) {
296 return true;
297 }
298 // New.
299 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
300 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc' ) !== false ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-' ) === false ) ) {
301 return true;
302 }
303
304 return false;
305 }
306
307 /**
308 * Check if this Booking > Add booking page
309 *
310 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
311 *
312 * @return boolean true | false
313 */
314 function wpbc_is_new_booking_page( $server_param = 'REQUEST_URI' ) {
315 // Old.
316 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
317 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-reservation' ) !== false ) ) {
318 return true;
319 }
320 // New.
321 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
322 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-new' ) !== false ) ) {
323 return true;
324 }
325
326 return false;
327 }
328
329 /**
330 * Check if this WP Booking Calendar > Settings > Booking Form page
331 *
332 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
333 *
334 * @return boolean true | false
335 */
336 function wpbc_is_settings_form_page( $server_param = 'REQUEST_URI' ) {
337 // Regular user overwrite settings.
338
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 ], 'page=wpbc-settings' ) !== false ) && ( ( strpos( $_SERVER[ $server_param ], '&tab=form' ) !== false ) || ( ( class_exists( 'wpdev_bk_multiuser' ) ) && ( ! empty( $_REQUEST['tab'] ) ) && ( 'form' === $_REQUEST['tab'] ) ) ) ) {
341 return true;
342 }
343
344 return false;
345 }
346
347
348 /**
349 * Check if this WP Booking Calendar > Settings > Booking Form page
350 *
351 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
352 *
353 * @return boolean true | false
354 */
355 function wpbc_is_settings_color_themes_page( $server_param = 'REQUEST_URI' ) {
356 // Regular user overwrite settings.
357
358 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
359 if ( ( is_admin() ) && ( false !== strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) ) && ( false !== strpos( $_SERVER[ $server_param ], '&tab=color_themes' ) ) ) {
360 return true;
361 }
362
363 return false;
364 }
365
366 /**
367 * Check if this Booking > Availability page
368 *
369 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
370 *
371 * @return boolean true | false
372 */
373 function wpbc_is_availability_page( $server_param = 'REQUEST_URI' ) {
374
375 // New.
376 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
377 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-availability' ) !== false ) ) {
378 return true;
379 }
380
381 return false;
382 }
383
384
385 /**
386 * Check if this Booking > Setup page
387 *
388 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
389 *
390 * @return boolean true | false
391 */
392 function wpbc_is_setup_wizard_page( $server_param = 'REQUEST_URI' ) { // FixIn: 9.8.0.1.
393
394 // New.
395 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
396 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-setup' ) !== false ) ) {
397 return true;
398 }
399
400 return false;
401 }
402
403 /**
404 * Check if this Booking > Resources page
405 *
406 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
407 *
408 * @return boolean true | false
409 */
410 function wpbc_is_resources_page( $server_param = 'REQUEST_URI' ) {
411
412 // Old.
413 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
414 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-resources' ) !== false ) ) {
415 return true;
416 }
417 // New.
418 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
419 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-resources' ) !== false ) ) {
420 return true;
421 }
422
423 return false;
424 }
425
426 /**
427 * Check if this Booking > Settings page
428 *
429 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
430 *
431 * @return boolean true | false
432 */
433 function wpbc_is_settings_page( $server_param = 'REQUEST_URI' ) {
434
435 // Old.
436 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
437 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-option' ) !== false ) ) {
438 return true;
439 }
440 // New.
441 // 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() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) ) {
443 return true;
444 }
445
446 return false;
447 }
448
449
450 // -----------------------------------------------------------------------------------------------------------------
451 // == support ==
452 // ---------------------------------------------------------------------------------------------------------------------
453
454 /**
455 * Transform the REQUEST parameters (GET and POST) into URL
456 *
457 * @param $page_param
458 * @param $exclude_params
459 * @param $only_these_parameters
460 * @param $is_escape_url
461 * @param $only_get
462 *
463 * @return string|null
464 */
465 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
466
467 $exclude_params[] = 'page';
468 $exclude_params[] = 'post_type';
469
470 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
471 if ( isset( $_GET['page'] ) ) {
472 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
473 $page_param = $_GET['page'];
474 }
475 $get_paramaters = array( 'page' => $page_param );
476 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
477 $check_params = ( $only_get ) ? $_GET : $_REQUEST;
478
479
480 foreach ( $check_params as $prm_key => $prm_value ) {
481
482 // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 )
483 if (
484 ( is_string( $prm_value ) )
485 || ( is_numeric( $prm_value ) )
486 ){
487
488 // Check about Too long parameters, if it exists then reset it.
489 if ( strlen( $prm_value ) > 1000 ) {
490 $prm_value = '';
491 }
492
493 if ( ! in_array( $prm_key, $exclude_params ) ) {
494 if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) ) {
495 $get_paramaters[ $prm_key ] = $prm_value;
496 }
497 }
498
499 }
500 }
501
502 $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) );
503
504 if ( $is_escape_url ) {
505 $url = esc_url_raw( $url ); // FixIn: 8.1.1.7.
506 }
507
508 return $url;
509 }
510
511
512 function wpbc_left_vertival_nav__get_tab_url( $page_tag, $tab_name, $subtab_name = false, $tags = array( 'tab' => 'tab', 'subtab' => 'subtab' ) ) {
513
514 if ( false === $subtab_name ) {
515 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $tags['tab'] => $tab_name, ), 'admin.php' ) ) );
516 } else {
517 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $tags['tab'] => $tab_name, $tags['subtab'] => $subtab_name, ), 'admin.php' ) ) );
518 }
519 }
520
521 /**
522 * Get back URL for going from edit season filter or rate to specfic main page.
523 *
524 * @return string|null
525 */
526 function wpbc_get_back_button_url__for_seasons() {
527
528 $page_params_arr = array(
529 'page' => 'wpbc-availability',
530 'page_num' => 1,
531 );
532
533 if ( ! empty( $_REQUEST['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
534 $page_params_arr['page'] = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
535 }
536 if ( ! empty( $_REQUEST['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
537 $page_params_arr['tab'] = sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
538 }
539 if ( ! empty( $_REQUEST['page_num'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
540 $page_params_arr['page_num'] = intval( $_REQUEST['page_num'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
541 }
542
543 $back_url = admin_url(
544 add_query_arg(
545 $page_params_arr,
546 'admin.php'
547 )
548 );
549 return $back_url;
550 }
551