PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
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.10.2, at includes/_functions/admin_menu_url.php

490 lines 18.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 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 * Check if this Booking > Availability page
349 *
350 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
351 *
352 * @return boolean true | false
353 */
354 function wpbc_is_availability_page( $server_param = 'REQUEST_URI' ) {
355
356 // New.
357 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
358 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-availability' ) !== false ) ) {
359 return true;
360 }
361
362 return false;
363 }
364
365
366 /**
367 * Check if this Booking > Setup 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_setup_wizard_page( $server_param = 'REQUEST_URI' ) { // FixIn: 9.8.0.1.
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-setup' ) !== false ) ) {
378 return true;
379 }
380
381 return false;
382 }
383
384 /**
385 * Check if this Booking > Resources page
386 *
387 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
388 *
389 * @return boolean true | false
390 */
391 function wpbc_is_resources_page( $server_param = 'REQUEST_URI' ) {
392
393 // Old.
394 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
395 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-resources' ) !== false ) ) {
396 return true;
397 }
398 // New.
399 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
400 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-resources' ) !== false ) ) {
401 return true;
402 }
403
404 return false;
405 }
406
407 /**
408 * Check if this Booking > Settings page
409 *
410 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
411 *
412 * @return boolean true | false
413 */
414 function wpbc_is_settings_page( $server_param = 'REQUEST_URI' ) {
415
416 // Old.
417 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
418 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'wpdev-booking.phpwpdev-booking-option' ) !== false ) ) {
419 return true;
420 }
421 // New.
422 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
423 if ( ( is_admin() ) && ( strpos( $_SERVER[ $server_param ], 'page=wpbc-settings' ) !== false ) ) {
424 return true;
425 }
426
427 return false;
428 }
429
430
431 // -----------------------------------------------------------------------------------------------------------------
432 // == support ==
433 // ---------------------------------------------------------------------------------------------------------------------
434
435 /**
436 * Transform the REQUEST parameters (GET and POST) into URL
437 *
438 * @param $page_param
439 * @param $exclude_params
440 * @param $only_these_parameters
441 * @param $is_escape_url
442 * @param $only_get
443 *
444 * @return string|null
445 */
446 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
447
448 $exclude_params[] = 'page';
449 $exclude_params[] = 'post_type';
450
451 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
452 if ( isset( $_GET['page'] ) ) {
453 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
454 $page_param = $_GET['page'];
455 }
456 $get_paramaters = array( 'page' => $page_param );
457 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
458 $check_params = ( $only_get ) ? $_GET : $_REQUEST;
459
460
461 foreach ( $check_params as $prm_key => $prm_value ) {
462
463 // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 )
464 if (
465 ( is_string( $prm_value ) )
466 || ( is_numeric( $prm_value ) )
467 ){
468
469 // Check about Too long parameters, if it exists then reset it.
470 if ( strlen( $prm_value ) > 1000 ) {
471 $prm_value = '';
472 }
473
474 if ( ! in_array( $prm_key, $exclude_params ) ) {
475 if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) ) {
476 $get_paramaters[ $prm_key ] = $prm_value;
477 }
478 }
479
480 }
481 }
482
483 $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) );
484
485 if ( $is_escape_url ) {
486 $url = esc_url_raw( $url ); // FixIn: 8.1.1.7.
487 }
488
489 return $url;
490 }