PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.7.3
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.7.3
4.7.3 4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 All 93 releases
cookiebot / src / lib / Settings_Page_Tab.php

Settings_Page_Tab.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 4.7.3, at src/lib/Settings_Page_Tab.php

138 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cybot\cookiebot\lib;
4
5 use InvalidArgumentException;
6
7 class Settings_Page_Tab {
8
9
10 /**
11 * @var string
12 */
13 private $name;
14 /**
15 * @var string
16 */
17 private $label;
18 /**
19 * @var string
20 */
21 private $settings_fields_option_group;
22 /**
23 * @var string
24 */
25 private $page_name;
26 /**
27 * @var bool
28 */
29 private $is_active;
30 /**
31 * @var bool
32 */
33 private $has_submit_button;
34
35 /**
36 * @param $name
37 * @param $label
38 * @param $settings_fields_option_group
39 * @param $page_name
40 * @param bool $has_submit_button
41 *
42 * @throws InvalidArgumentException
43 */
44 public function __construct(
45 $name,
46 $label,
47 $settings_fields_option_group,
48 $page_name,
49 $has_submit_button = true
50 ) {
51 if ( ! is_string( $name ) || empty( $name ) ) {
52 throw new InvalidArgumentException( 'The constructor argument "name" is a required string ' );
53 }
54 if ( ! is_string( $label ) || empty( $label ) ) {
55 throw new InvalidArgumentException( 'The constructor argument "label" is a required string ' );
56 }
57 if ( ! is_string( $settings_fields_option_group ) || empty( $settings_fields_option_group ) ) {
58 throw new InvalidArgumentException( 'The constructor argument "settings_fields_option_group" is a required string ' );
59 }
60 if ( ! is_string( $page_name ) || empty( $page_name ) ) {
61 throw new InvalidArgumentException( 'The constructor argument "page_name" is a required string ' );
62 }
63
64 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
65 $this->is_active = isset( $_GET['tab'] ) && $_GET['tab'] === $name;
66 $this->name = $name;
67 $this->label = $label;
68 $this->settings_fields_option_group = $settings_fields_option_group;
69 $this->page_name = $page_name;
70 $this->has_submit_button = $has_submit_button;
71 }
72
73 /**
74 * @return string
75 */
76 public function get_name() {
77 return $this->name;
78 }
79
80 /**
81 * @return string
82 */
83 public function get_label() {
84 return $this->label;
85 }
86
87 /**
88 * @return string
89 */
90 public function get_settings_fields_option_group() {
91 return $this->settings_fields_option_group;
92 }
93
94 /**
95 * @return string
96 */
97 public function get_page_name() {
98 return $this->page_name;
99 }
100
101 /**
102 * @return bool
103 */
104 public function is_active() {
105 return $this->is_active;
106 }
107
108 /**
109 * @param bool $is_active
110 */
111 public function set_is_active( $is_active ) {
112 $this->is_active = $is_active;
113 }
114
115 public function get_tab_href() {
116 $query = array(
117 'page' => $this->page_name,
118 'tab' => $this->name,
119 );
120
121 return add_query_arg( $query, admin_url( 'admin.php' ) );
122 }
123
124 /**
125 * @return string
126 */
127 public function get_classes() {
128 return $this->is_active ? 'nav-tab nav-tab-active' : 'nav-tab';
129 }
130
131 /**
132 * @return bool
133 */
134 public function has_submit_button() {
135 return $this->has_submit_button;
136 }
137 }
138