PluginProbe
Bookit — Booking & Appointment Calendar / 2.6.0.5
Bookit — Booking & Appointment Calendar v2.6.0.5
2.6.0.5 2.6.0.4 2.6.0.3 2.6.0.2 2.6.0.1 2.6.0 trunk 1.2 1.2.2 1.2.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 All 62 releases
bookit / src / Bookit / Admin / Settings.php

Settings.php in Bookit — Booking & Appointment Calendar 2.6.0.5, at src/Bookit/Admin/Settings.php

104 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Bookit\Admin;
4
5 /**
6 * Class Settings
7 *
8 * @since 2.5.0
9 *
10 * @package Bookit\Admin
11 */
12 class Settings {
13
14 /**
15 * Current page ID (or false if not registered with this controller).
16 *
17 * @since 2.5.0
18 *
19 * @var string|null
20 */
21 private $current_page = null;
22
23 /**
24 * Bookit settings page slug.
25 *
26 * @var string
27 */
28 public static $settings_page_id = 'bookit-settings';
29
30 /**
31 * Gets the URL to the Bookit settings page with optional query arguments and anchor links.
32 *
33 * @since 2.5.0
34 *
35 * @param array $args Query arguments to add to the URL.
36 * @param string $anchor Anchor link to append to the URL (e.g., 'payments').
37 *
38 * @return string The URL to the Bookit settings page with query arguments and anchor link.
39 */
40 public function get_url( array $args = [], $anchor = '' ) {
41 $defaults = [
42 'page' => static::$settings_page_id,
43 ];
44
45 // Allow the link to be "changed" on the fly.
46 $args = wp_parse_args( $args, $defaults );
47
48 $wp_url = is_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'admin.php' );
49
50 // Keep the resulting URL args clean.
51 $url = add_query_arg( $args, $wp_url );
52
53 // Add the anchor link if provided.
54 if ( ! empty( $anchor ) ) {
55 $url .= '#' . ltrim( $anchor, '#' );
56 }
57
58 /**
59 * Filters the URL to the Bookit settings page.
60 *
61 * @since 2.5.0
62 *
63 * @param string $url The URL to the Bookit settings page.
64 */
65 return apply_filters( 'bookit_settings_url', $url );
66 }
67
68 /**
69 * Get the current page.
70 *
71 * @since 2.5.0
72 *
73 * @return string|boolean Current page or false if not registered with this controller.
74 */
75 public function get_current_page() {
76 if ( is_null( $this->current_page ) ) {
77 $this->determine_current_page();
78 }
79
80 return $this->current_page;
81 }
82
83 /**
84 * Determine the current page.
85 *
86 * @since 2.5.0
87 *
88 * @return string|boolean Current page or false if not registered with this controller.
89 */
90 public function determine_current_page() {
91 $current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
92
93 if ( is_null( $current_screen ) ) {
94 $this->current_page = bookit_get_request_var( 'page' );
95
96 return $this->current_page;
97 }
98
99 $this->current_page = $current_screen->id;
100
101 return $this->current_page;
102 }
103 }
104