buffer
1 year ago
script_loader_tag
1 year ago
traits
1 year ago
Account_Service.php
1 year ago
Consent_API_Helper.php
1 year ago
Cookie_Consent.php
1 year ago
Cookie_Consent_Interface.php
1 year ago
Cookiebot_Activated.php
1 year ago
Cookiebot_Admin_Links.php
1 year ago
Cookiebot_Automatic_Updates.php
1 year ago
Cookiebot_Deactivated.php
1 year ago
Cookiebot_Frame.php
1 year ago
Cookiebot_Javascript_Helper.php
1 year ago
Cookiebot_Review.php
1 year ago
Cookiebot_WP.php
1 year ago
Dependency_Container.php
1 year ago
Settings_Page_Tab.php
1 year ago
Settings_Service.php
1 year ago
Settings_Service_Interface.php
1 year ago
Supported_Languages.php
1 year ago
Supported_Regions.php
1 year ago
WP_Rocket_Helper.php
1 year ago
Widgets.php
1 year ago
global-deprecations.php
1 year ago
helper.php
1 year ago
Settings_Page_Tab.php
138 lines
| 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 |