buffer
4 years ago
script_loader_tag
4 years ago
traits
4 years ago
Consent_API_Helper.php
4 years ago
Cookie_Consent.php
4 years ago
Cookie_Consent_Interface.php
4 years ago
Cookiebot_Activated.php
4 years ago
Cookiebot_Automatic_Updates.php
4 years ago
Cookiebot_Deactivated.php
4 years ago
Cookiebot_Javascript_Helper.php
4 years ago
Cookiebot_WP.php
3 years ago
Dependency_Container.php
4 years ago
Settings_Page_Tab.php
4 years ago
Settings_Service.php
4 years ago
Settings_Service_Interface.php
4 years ago
Supported_Languages.php
4 years ago
Supported_Regions.php
3 years ago
WP_Rocket_Helper.php
4 years ago
Widgets.php
4 years ago
global-deprecations.php
4 years ago
helper.php
4 years ago
Settings_Page_Tab.php
139 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | |
| 7 | class Settings_Page_Tab { |
| 8 | |
| 9 | /** |
| 10 | * @var string |
| 11 | */ |
| 12 | private $name; |
| 13 | /** |
| 14 | * @var string |
| 15 | */ |
| 16 | private $label; |
| 17 | /** |
| 18 | * @var string |
| 19 | */ |
| 20 | private $settings_fields_option_group; |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | private $page_name; |
| 25 | /** |
| 26 | * @var bool |
| 27 | */ |
| 28 | private $is_active; |
| 29 | /** |
| 30 | * @var bool |
| 31 | */ |
| 32 | private $has_submit_button; |
| 33 | |
| 34 | /** |
| 35 | * @param $name |
| 36 | * @param $label |
| 37 | * @param $settings_fields_option_group |
| 38 | * @param $page_name |
| 39 | * @param bool $has_submit_button |
| 40 | * |
| 41 | * @throws InvalidArgumentException |
| 42 | */ |
| 43 | public function __construct( |
| 44 | $name, |
| 45 | $label, |
| 46 | $settings_fields_option_group, |
| 47 | $page_name, |
| 48 | $has_submit_button = true |
| 49 | ) { |
| 50 | if ( ! is_string( $name ) || empty( $name ) ) { |
| 51 | throw new InvalidArgumentException( 'The constructor argument "name" is a required string ' ); |
| 52 | } |
| 53 | if ( ! is_string( $label ) || empty( $label ) ) { |
| 54 | throw new InvalidArgumentException( 'The constructor argument "label" is a required string ' ); |
| 55 | } |
| 56 | if ( ! is_string( $settings_fields_option_group ) || empty( $settings_fields_option_group ) ) { |
| 57 | throw new InvalidArgumentException( 'The constructor argument "settings_fields_option_group" is a required string ' ); |
| 58 | } |
| 59 | if ( ! is_string( $page_name ) || empty( $page_name ) ) { |
| 60 | throw new InvalidArgumentException( 'The constructor argument "page_name" is a required string ' ); |
| 61 | } |
| 62 | |
| 63 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 64 | $this->is_active = isset( $_GET['tab'] ) && $_GET['tab'] === $name; |
| 65 | $this->name = $name; |
| 66 | $this->label = $label; |
| 67 | $this->settings_fields_option_group = $settings_fields_option_group; |
| 68 | $this->page_name = $page_name; |
| 69 | $this->has_submit_button = $has_submit_button; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @return string |
| 74 | */ |
| 75 | public function get_name() { |
| 76 | return $this->name; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return string |
| 81 | */ |
| 82 | public function get_label() { |
| 83 | return $this->label; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @return string |
| 88 | */ |
| 89 | public function get_settings_fields_option_group() { |
| 90 | return $this->settings_fields_option_group; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return string |
| 95 | */ |
| 96 | public function get_page_name() { |
| 97 | return $this->page_name; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @return bool |
| 102 | */ |
| 103 | public function is_active() { |
| 104 | return $this->is_active; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @param bool $is_active |
| 109 | */ |
| 110 | public function set_is_active( $is_active ) { |
| 111 | $this->is_active = $is_active; |
| 112 | } |
| 113 | |
| 114 | public function get_tab_href() { |
| 115 | $query = http_build_query( |
| 116 | array( |
| 117 | 'page' => $this->page_name, |
| 118 | 'tab' => $this->name, |
| 119 | ) |
| 120 | ); |
| 121 | return admin_url( 'admin.php?' . $query ); |
| 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 | } |
| 139 |