Settings_Config.php
634 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\addons\config; |
| 4 | |
| 5 | use cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Addon; |
| 6 | use cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Plugin_Addon; |
| 7 | use cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Theme_Addon; |
| 8 | use cybot\cookiebot\addons\controller\addons\jetpack\Jetpack; |
| 9 | use cybot\cookiebot\addons\controller\addons\jetpack\widget\Base_Jetpack_Widget; |
| 10 | use cybot\cookiebot\lib\Settings_Page_Tab; |
| 11 | use cybot\cookiebot\lib\Settings_Service_Interface; |
| 12 | use cybot\cookiebot\lib\Cookiebot_WP; |
| 13 | use Exception; |
| 14 | use InvalidArgumentException; |
| 15 | use ReflectionClass; |
| 16 | use function cybot\cookiebot\lib\asset_url; |
| 17 | use function cybot\cookiebot\lib\cookiebot_addons_get_dropdown_languages; |
| 18 | use function cybot\cookiebot\lib\get_view_html; |
| 19 | use function cybot\cookiebot\lib\include_view; |
| 20 | |
| 21 | class Settings_Config { |
| 22 | |
| 23 | /** |
| 24 | * @var Settings_Service_Interface |
| 25 | */ |
| 26 | protected $settings_service; |
| 27 | |
| 28 | const ADMIN_SLUG = 'cookiebot-addons'; |
| 29 | |
| 30 | /** |
| 31 | * Settings_Config constructor. |
| 32 | * |
| 33 | * @param Settings_Service_Interface $settings_service |
| 34 | * |
| 35 | * @since 1.3.0 |
| 36 | */ |
| 37 | public function __construct( Settings_Service_Interface $settings_service ) { |
| 38 | $this->settings_service = $settings_service; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Load data for settings page |
| 43 | * |
| 44 | * @since 1.3.0 |
| 45 | */ |
| 46 | public function load() { |
| 47 | add_action( 'admin_menu', array( $this, 'add_submenu' ), 2 ); |
| 48 | add_action( 'admin_init', array( $this, 'register_settings' ) ); |
| 49 | add_action( 'admin_enqueue_scripts', array( $this, 'add_wp_admin_style_script' ) ); |
| 50 | add_action( |
| 51 | 'update_option_cookiebot_available_addons', |
| 52 | array( |
| 53 | $this, |
| 54 | 'post_hook_available_addons_update_option', |
| 55 | ), |
| 56 | 10, |
| 57 | 3 |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Registers submenu in options menu. |
| 63 | * |
| 64 | * @since 1.3.0 |
| 65 | */ |
| 66 | public function add_submenu() { |
| 67 | add_submenu_page( |
| 68 | 'cookiebot', |
| 69 | esc_html__( 'Plugins', 'cookiebot' ), |
| 70 | esc_html__( 'Plugins', 'cookiebot' ), |
| 71 | 'manage_options', |
| 72 | 'cookiebot-addons', |
| 73 | array( |
| 74 | $this, |
| 75 | 'setting_page', |
| 76 | ), |
| 77 | 2 |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Load css styling to the settings page |
| 83 | * |
| 84 | * @throws InvalidArgumentException |
| 85 | * @since 1.3.0 |
| 86 | */ |
| 87 | public function add_wp_admin_style_script( $hook ) { |
| 88 | if ( $hook !== 'cookiebot_page_cookiebot-addons' ) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | wp_enqueue_script( |
| 93 | 'cookiebot_tiptip_js', |
| 94 | asset_url( 'js/backend/jquery.tipTip.js' ), |
| 95 | array( 'jquery' ), |
| 96 | '1.8', |
| 97 | true |
| 98 | ); |
| 99 | wp_enqueue_script( |
| 100 | 'cookiebot_addons_custom_js', |
| 101 | asset_url( 'js/backend/prior-consent-settings.js' ), |
| 102 | array( 'jquery' ), |
| 103 | '1.8', |
| 104 | true |
| 105 | ); |
| 106 | wp_localize_script( |
| 107 | 'cookiebot_addons_custom_js', |
| 108 | 'php', |
| 109 | array( 'remove_link' => ' <a href="" class="submitdelete deletion">' . esc_html__( 'Remove language', 'cookiebot' ) . '</a>' ) |
| 110 | ); |
| 111 | wp_enqueue_style( |
| 112 | 'cookiebot_addons_custom_css', |
| 113 | asset_url( 'css/backend/addons_page.css' ), |
| 114 | null, |
| 115 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 116 | ); |
| 117 | wp_enqueue_style( |
| 118 | 'cookiebot_admin_css', |
| 119 | asset_url( 'css/backend/cookiebot_admin_main.css' ), |
| 120 | null, |
| 121 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Registers addons for settings page. |
| 127 | * |
| 128 | * @throws Exception |
| 129 | * @since 1.3.0 |
| 130 | */ |
| 131 | public function register_settings() { |
| 132 | global $pagenow; |
| 133 | |
| 134 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 135 | if ( ( isset( $_GET['page'] ) && $_GET['page'] === 'cookiebot-addons' ) || $pagenow === 'options.php' ) { |
| 136 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 137 | if ( isset( $_GET['tab'] ) && 'unavailable_addons' === $_GET['tab'] ) { |
| 138 | $this->register_unavailable_addons(); |
| 139 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 140 | } elseif ( ( isset( $_GET['tab'] ) && 'available_addons' === $_GET['tab'] ) ) { |
| 141 | $this->register_available_addons(); |
| 142 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 143 | } elseif ( ( isset( $_GET['tab'] ) && 'jetpack' === $_GET['tab'] ) ) { |
| 144 | $this->register_jetpack_addon(); |
| 145 | } else { |
| 146 | $this->register_addons_info(); |
| 147 | } |
| 148 | |
| 149 | if ( $pagenow === 'options.php' ) { |
| 150 | $this->register_jetpack_addon(); |
| 151 | $this->register_available_addons(); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Register addons info |
| 158 | * |
| 159 | * @throws Exception |
| 160 | * @since 1.3.0 |
| 161 | */ |
| 162 | private function register_addons_info() { |
| 163 | add_settings_section( |
| 164 | 'info_addons', |
| 165 | '', |
| 166 | array( |
| 167 | $this, |
| 168 | 'header_addons_info', |
| 169 | ), |
| 170 | 'cookiebot-addons' |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Returns header for info tab |
| 176 | * |
| 177 | * @since 1.3.0 |
| 178 | */ |
| 179 | public function header_addons_info() { |
| 180 | include_view( 'admin/settings/prior-consent/partials/info-tab-header.php' ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Register available addons |
| 185 | * |
| 186 | * @throws Exception |
| 187 | * @since 1.3.0 |
| 188 | */ |
| 189 | private function register_available_addons() { |
| 190 | add_settings_section( |
| 191 | 'available_addons', |
| 192 | '', |
| 193 | array( |
| 194 | $this, |
| 195 | 'header_available_addons', |
| 196 | ), |
| 197 | 'cookiebot-addons' |
| 198 | ); |
| 199 | |
| 200 | /** @var Base_Cookiebot_Addon $addon */ |
| 201 | foreach ( $this->settings_service->get_addons() as $addon ) { |
| 202 | if ( $addon->is_addon_installed() && $addon->is_addon_activated() ) { |
| 203 | add_settings_field( |
| 204 | $addon::OPTION_NAME, |
| 205 | get_view_html( |
| 206 | 'admin/settings/prior-consent/partials/extra-information.php', |
| 207 | array( |
| 208 | 'label' => $addon::ADDON_NAME, |
| 209 | 'extra_information_lines' => $addon->get_extra_information(), |
| 210 | ) |
| 211 | ), |
| 212 | array( |
| 213 | $this, |
| 214 | 'available_addon_callback', |
| 215 | ), |
| 216 | 'cookiebot-addons', |
| 217 | 'available_addons', |
| 218 | array( |
| 219 | 'addon' => $addon, |
| 220 | ) |
| 221 | ); |
| 222 | |
| 223 | register_setting( |
| 224 | 'cookiebot_available_addons', |
| 225 | 'cookiebot_available_addons', |
| 226 | array( |
| 227 | $this, |
| 228 | 'sanitize_cookiebot', |
| 229 | ) |
| 230 | ); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Register jetpack addon - new tab for jetpack specific settings |
| 237 | * |
| 238 | * @throws Exception |
| 239 | * @since 1.3.0 |
| 240 | */ |
| 241 | private function register_jetpack_addon() { |
| 242 | add_settings_section( |
| 243 | 'jetpack_addon', |
| 244 | '', |
| 245 | array( |
| 246 | $this, |
| 247 | 'jetpack_addons_header_callback', |
| 248 | ), |
| 249 | 'cookiebot-addons' |
| 250 | ); |
| 251 | |
| 252 | /** @var Jetpack $addon */ |
| 253 | foreach ( $this->settings_service->get_addons() as $addon ) { |
| 254 | if ( 'Jetpack' === ( new ReflectionClass( $addon ) )->getShortName() ) { |
| 255 | if ( $addon->is_addon_installed() && $addon->is_addon_activated() ) { |
| 256 | foreach ( $addon->get_widgets() as $widget ) { |
| 257 | add_settings_field( |
| 258 | $widget->get_widget_option_name(), |
| 259 | get_view_html( |
| 260 | 'admin/settings/prior-consent/partials/extra-information.php', |
| 261 | array( |
| 262 | 'label' => $widget->get_label(), |
| 263 | 'extra_information_lines' => $widget->get_extra_information(), |
| 264 | ) |
| 265 | ), |
| 266 | array( |
| 267 | $this, |
| 268 | 'jetpack_addon_callback', |
| 269 | ), |
| 270 | 'cookiebot-addons', |
| 271 | 'jetpack_addon', |
| 272 | array( |
| 273 | 'widget' => $widget, |
| 274 | 'addon' => $addon, |
| 275 | ) |
| 276 | ); |
| 277 | |
| 278 | register_setting( 'cookiebot_jetpack_addon', 'cookiebot_jetpack_addon' ); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Registers unavailabe addons |
| 287 | * |
| 288 | * @throws Exception |
| 289 | * @version 2.1.3 |
| 290 | * @since 1.3.0 |
| 291 | */ |
| 292 | private function register_unavailable_addons() { |
| 293 | add_settings_section( |
| 294 | 'unavailable_addons', |
| 295 | '', |
| 296 | array( |
| 297 | $this, |
| 298 | 'unavailable_addons_header_callback', |
| 299 | ), |
| 300 | 'cookiebot-addons' |
| 301 | ); |
| 302 | |
| 303 | $addons = $this->settings_service->get_addons(); |
| 304 | |
| 305 | /** @var Base_Cookiebot_Addon $addon */ |
| 306 | foreach ( $addons as $addon ) { |
| 307 | if ( ! $addon->is_addon_installed() || ! $addon->is_addon_activated() ) { |
| 308 | // not installed plugins |
| 309 | add_settings_field( |
| 310 | $addon::ADDON_NAME, |
| 311 | get_view_html( |
| 312 | 'admin/settings/prior-consent/partials/extra-information.php', |
| 313 | array( |
| 314 | 'label' => $addon::ADDON_NAME, |
| 315 | 'extra_information_lines' => $addon->get_extra_information(), |
| 316 | ) |
| 317 | ), |
| 318 | array( |
| 319 | $this, |
| 320 | 'unavailable_addon_settings_field_callback', |
| 321 | ), |
| 322 | 'cookiebot-addons', |
| 323 | 'unavailable_addons', |
| 324 | array( 'addon' => $addon ) |
| 325 | ); |
| 326 | register_setting( $addon::OPTION_NAME, 'cookiebot_unavailable_addons' ); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Jetpack tab - header |
| 333 | * |
| 334 | * @throws InvalidArgumentException |
| 335 | * @since 1.3.0 |
| 336 | */ |
| 337 | public function jetpack_addons_header_callback() { |
| 338 | include_view( 'admin/settings/prior-consent/jetpack-widgets/tab-header.php' ); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Jetpack tab - widget callback |
| 343 | * |
| 344 | * @param $args array Information about the widget addon and the option |
| 345 | * |
| 346 | * @throws InvalidArgumentException |
| 347 | * @since 1.3.0 |
| 348 | */ |
| 349 | public function jetpack_addon_callback( $args ) { |
| 350 | $widget = isset( $args['widget'] ) ? $args['widget'] : null; |
| 351 | $addon = isset( $args['addon'] ) ? $args['addon'] : null; |
| 352 | |
| 353 | if ( ! is_a( $widget, Base_Jetpack_Widget::class ) ) { |
| 354 | throw new InvalidArgumentException(); |
| 355 | } |
| 356 | |
| 357 | if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) { |
| 358 | throw new InvalidArgumentException(); |
| 359 | } |
| 360 | |
| 361 | $widget_is_enabled = $widget->is_widget_enabled(); |
| 362 | $widget_placeholder_is_enabled = $widget->is_widget_placeholder_enabled(); |
| 363 | $widget_default_placeholder = $widget->get_widget_default_placeholder(); |
| 364 | $widget_option_name = $widget->get_widget_option_name(); |
| 365 | $widget_placeholders_array = $widget->get_widget_placeholders(); |
| 366 | $widget_placeholders_array_keys = array_keys( $widget_placeholders_array ); |
| 367 | $first_placeholder_language = isset( $widget_placeholders_array_keys[0] ) |
| 368 | ? $widget_placeholders_array_keys[0] |
| 369 | : null; |
| 370 | $site_default_languages_dropdown_html = 'cookiebot_jetpack_addon[' . $widget_option_name . '][placeholder][languages][site-default]'; |
| 371 | $widget_placeholders = array_map( |
| 372 | function( $language, $placeholder ) use ( $widget_option_name, $widget_placeholders_array, $first_placeholder_language ) { |
| 373 | $removable = $first_placeholder_language !== $language; |
| 374 | $option_name = 'cookiebot_jetpack_addon[' . $widget_option_name . '][placeholder][languages][' . $language . ']'; |
| 375 | $languages_dropdown_html = cookiebot_addons_get_dropdown_languages( |
| 376 | 'placeholder_select_language', |
| 377 | $option_name, |
| 378 | $language |
| 379 | ); |
| 380 | return array( |
| 381 | 'name' => $option_name, |
| 382 | 'removable' => $removable, |
| 383 | 'language' => $language, |
| 384 | 'placeholder' => $placeholder, |
| 385 | 'languages_dropdown_html' => $languages_dropdown_html, |
| 386 | ); |
| 387 | }, |
| 388 | array_keys( $widget_placeholders_array ), |
| 389 | array_values( $widget_placeholders_array ) |
| 390 | ); |
| 391 | $placeholder_helper = $addon->get_placeholder_helper(); |
| 392 | $placeholders_html = $widget->widget_has_placeholder() |
| 393 | ? get_view_html( |
| 394 | 'admin/settings/prior-consent/partials/placeholder-submitboxes.php', |
| 395 | array( |
| 396 | 'placeholders' => $widget_placeholders, |
| 397 | 'placeholder_helper' => $placeholder_helper, |
| 398 | ) |
| 399 | ) |
| 400 | : get_view_html( |
| 401 | 'admin/settings/prior-consent/partials/placeholder-submitbox-default.php', |
| 402 | array( |
| 403 | 'site_default_languages_dropdown_html' => $site_default_languages_dropdown_html, |
| 404 | 'name' => 'cookiebot_jetpack_addon[' . $widget_option_name . '][placeholder][languages][site-default]', |
| 405 | 'default_placeholder' => $widget_default_placeholder, |
| 406 | 'placeholder_helper' => $placeholder_helper, |
| 407 | ) |
| 408 | ); |
| 409 | |
| 410 | $view_args = array( |
| 411 | 'widget_option_name' => $widget_option_name, |
| 412 | 'widget_is_enabled' => $widget_is_enabled, |
| 413 | 'widget_cookie_types' => $widget->get_widget_cookie_types(), |
| 414 | 'widget_placeholder_is_enabled' => $widget_placeholder_is_enabled, |
| 415 | 'placeholders_html' => $placeholders_html, |
| 416 | ); |
| 417 | |
| 418 | include_view( 'admin/settings/prior-consent/jetpack-widgets/tab.php', $view_args ); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Returns header for installed plugins |
| 423 | * |
| 424 | * @since 1.3.0 |
| 425 | */ |
| 426 | public function header_available_addons() { |
| 427 | include_view( 'admin/settings/prior-consent/available-addons/tab-header.php' ); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Available addon callback: |
| 432 | * - checkbox to enable |
| 433 | * - select field for cookie type |
| 434 | * |
| 435 | * @param $args |
| 436 | * |
| 437 | * @throws InvalidArgumentException |
| 438 | * @since 1.3.0 |
| 439 | */ |
| 440 | public function available_addon_callback( $args ) { |
| 441 | $addon = isset( $args['addon'] ) ? $args['addon'] : null; |
| 442 | |
| 443 | if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) { |
| 444 | throw new InvalidArgumentException(); |
| 445 | } |
| 446 | |
| 447 | $site_default_languages_dropdown_html = 'cookiebot_available_addons[' . $addon::OPTION_NAME . '][placeholder][languages][site-default]'; |
| 448 | $addon_placeholders_array = $addon->get_placeholders(); |
| 449 | $addon_placeholders_array_keys = array_keys( $addon_placeholders_array ); |
| 450 | $first_placeholder_language = isset( $addon_placeholders_array_keys[0] ) |
| 451 | ? $addon_placeholders_array_keys[0] |
| 452 | : null; |
| 453 | $addon_placeholders = array_map( |
| 454 | function( $language, $placeholder ) use ( $addon, $addon_placeholders_array, $first_placeholder_language ) { |
| 455 | $removable = $first_placeholder_language !== $language; |
| 456 | $option_name = 'cookiebot_available_addons[' . $addon::OPTION_NAME . '][placeholder][languages][' . $language . ']'; |
| 457 | $languages_dropdown_html = cookiebot_addons_get_dropdown_languages( |
| 458 | 'placeholder_select_language', |
| 459 | $option_name, |
| 460 | $language |
| 461 | ); |
| 462 | return array( |
| 463 | 'name' => $option_name, |
| 464 | 'removable' => $removable, |
| 465 | 'language' => $language, |
| 466 | 'placeholder' => $placeholder, |
| 467 | 'languages_dropdown_html' => $languages_dropdown_html, |
| 468 | ); |
| 469 | }, |
| 470 | $addon_placeholders_array_keys, |
| 471 | $addon_placeholders_array |
| 472 | ); |
| 473 | $placeholder_helper = $addon->get_placeholder_helper(); |
| 474 | $addon_extra_options_html = $addon->get_extra_addon_options_html(); |
| 475 | $placeholders_html = $addon->has_placeholder() |
| 476 | ? get_view_html( |
| 477 | 'admin/settings/prior-consent/partials/placeholder-submitboxes.php', |
| 478 | array( |
| 479 | 'placeholders' => $addon_placeholders, |
| 480 | 'placeholder_helper' => $placeholder_helper, |
| 481 | ) |
| 482 | ) |
| 483 | : get_view_html( |
| 484 | 'admin/settings/prior-consent/partials/placeholder-submitbox-default.php', |
| 485 | array( |
| 486 | 'site_default_languages_dropdown_html' => $site_default_languages_dropdown_html, |
| 487 | 'name' => 'cookiebot_available_addons[' . $addon::OPTION_NAME . '][placeholder][languages][site-default]', |
| 488 | 'default_placeholder' => $addon::DEFAULT_PLACEHOLDER_CONTENT, |
| 489 | 'placeholder_helper' => $placeholder_helper, |
| 490 | ) |
| 491 | ); |
| 492 | |
| 493 | $view_args = array( |
| 494 | 'addon_option_name' => $addon::OPTION_NAME, |
| 495 | 'addon_is_enabled' => $addon->is_addon_enabled(), |
| 496 | 'addon_cookie_types' => $addon->get_cookie_types(), |
| 497 | 'addon_placeholder_is_enabled' => $addon->is_placeholder_enabled(), |
| 498 | 'placeholders_html' => $placeholders_html, |
| 499 | 'addon_extra_options_html' => $addon_extra_options_html, |
| 500 | ); |
| 501 | |
| 502 | include_view( 'admin/settings/prior-consent/available-addons/tab.php', $view_args ); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * Returns header for unavailable plugins |
| 507 | * |
| 508 | * @throws InvalidArgumentException |
| 509 | * @since 1.3.0 |
| 510 | */ |
| 511 | public function unavailable_addons_header_callback() { |
| 512 | include_view( 'admin/settings/prior-consent/unavailable-addons/tab-header.php' ); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * @param $args |
| 517 | * |
| 518 | * @throws InvalidArgumentException |
| 519 | */ |
| 520 | public function unavailable_addon_settings_field_callback( $args ) { |
| 521 | $addon = $args['addon']; |
| 522 | |
| 523 | if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) { |
| 524 | throw new InvalidArgumentException(); |
| 525 | } |
| 526 | |
| 527 | $message = ''; |
| 528 | if ( ! $addon->is_addon_installed() ) { |
| 529 | if ( is_a( $addon, Base_Cookiebot_Plugin_Addon::class ) ) { |
| 530 | $message = __( 'The plugin is not installed.', 'cookiebot' ); |
| 531 | } |
| 532 | if ( is_a( $addon, Base_Cookiebot_Theme_Addon::class ) ) { |
| 533 | $message = __( 'The theme is not installed.', 'cookiebot' ); |
| 534 | } |
| 535 | } elseif ( ! $addon->is_addon_activated() ) { |
| 536 | if ( is_a( $addon, Base_Cookiebot_Plugin_Addon::class ) ) { |
| 537 | $message = __( 'The plugin is not activated.', 'cookiebot' ); |
| 538 | } |
| 539 | if ( is_a( $addon, Base_Cookiebot_Theme_Addon::class ) ) { |
| 540 | $message = __( 'The theme is not activated.', 'cookiebot' ); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | $view_args = array( |
| 545 | 'message' => $message, |
| 546 | ); |
| 547 | include_view( 'admin/settings/prior-consent/unavailable-addons/field.php', $view_args ); |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Build up settings page |
| 552 | * |
| 553 | * @throws InvalidArgumentException |
| 554 | * @since 1.3.0 |
| 555 | */ |
| 556 | public function setting_page() { |
| 557 | $addons_info_tab = new Settings_Page_Tab( |
| 558 | 'addons_info', |
| 559 | esc_html__( 'Info', 'cookiebot' ), |
| 560 | 'info_addons', |
| 561 | 'cookiebot-addons', |
| 562 | false |
| 563 | ); |
| 564 | $available_addons_tab = new Settings_Page_Tab( |
| 565 | 'available_addons', |
| 566 | esc_html__( 'Available Add-ons', 'cookiebot' ), |
| 567 | 'cookiebot_available_addons', |
| 568 | 'cookiebot-addons' |
| 569 | ); |
| 570 | $unavailable_addons_tab = new Settings_Page_Tab( |
| 571 | 'unavailable_addons', |
| 572 | esc_html__( 'Unavailable Add-ons', 'cookiebot' ), |
| 573 | 'cookiebot_not_installed_options', |
| 574 | 'cookiebot-addons', |
| 575 | false |
| 576 | ); |
| 577 | $settings_page_tabs = array( |
| 578 | $addons_info_tab, |
| 579 | $available_addons_tab, |
| 580 | $unavailable_addons_tab, |
| 581 | ); |
| 582 | if ( is_plugin_active( Jetpack::PLUGIN_FILE_PATH ) ) { |
| 583 | $settings_page_tabs[] = new Settings_Page_Tab( |
| 584 | 'jetpack', |
| 585 | esc_html__( 'Jetpack', 'cookiebot' ), |
| 586 | 'cookiebot_jetpack_addon', |
| 587 | 'cookiebot-addons' |
| 588 | ); |
| 589 | } |
| 590 | $active_tab = array_reduce( |
| 591 | $settings_page_tabs, |
| 592 | function( $active_tab, Settings_Page_Tab $settings_page_tab ) { |
| 593 | if ( ! is_null( $active_tab ) ) { |
| 594 | return $active_tab; |
| 595 | } |
| 596 | if ( $settings_page_tab->is_active() ) { |
| 597 | return $settings_page_tab; |
| 598 | } |
| 599 | return null; |
| 600 | }, |
| 601 | null |
| 602 | ); |
| 603 | if ( ! $active_tab ) { |
| 604 | $addons_info_tab->set_is_active( true ); |
| 605 | $active_tab = $addons_info_tab; |
| 606 | } |
| 607 | $view_args = array( |
| 608 | 'settings_page_tabs' => $settings_page_tabs, |
| 609 | 'active_tab' => $active_tab, |
| 610 | ); |
| 611 | include_view( 'admin/settings/prior-consent/page.php', $view_args ); |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Post action hook after enabling the addon on the settings page. |
| 616 | * |
| 617 | * @param $old_value |
| 618 | * @param $value |
| 619 | * @param $option_name |
| 620 | * |
| 621 | * @throws Exception |
| 622 | * @since 2.2.0 |
| 623 | */ |
| 624 | public function post_hook_available_addons_update_option( $old_value, $value, $option_name ) { |
| 625 | if ( is_array( $value ) ) { |
| 626 | foreach ( $value as $addon_option_name => $addon_settings ) { |
| 627 | if ( isset( $addon_settings['enabled'] ) ) { |
| 628 | $this->settings_service->post_hook_after_enabling_addon_on_settings_page( $addon_option_name ); |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 |