Settings_Config.php
633 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 | } elseif ( ( isset( $_GET['tab'] ) && 'jetpack' === $_GET['tab'] ) ) { |
| 143 | $this->register_jetpack_addon(); |
| 144 | }else{ |
| 145 | $this->register_addons_info(); |
| 146 | } |
| 147 | |
| 148 | if ( $pagenow === 'options.php' ) { |
| 149 | $this->register_jetpack_addon(); |
| 150 | $this->register_available_addons(); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Register addons info |
| 157 | * |
| 158 | * @throws Exception |
| 159 | * @since 1.3.0 |
| 160 | */ |
| 161 | private function register_addons_info() { |
| 162 | add_settings_section( |
| 163 | 'info_addons', |
| 164 | '', |
| 165 | array( |
| 166 | $this, |
| 167 | 'header_addons_info', |
| 168 | ), |
| 169 | 'cookiebot-addons' |
| 170 | ); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Returns header for info tab |
| 175 | * |
| 176 | * @since 1.3.0 |
| 177 | */ |
| 178 | public function header_addons_info() { |
| 179 | include_view( 'admin/settings/prior-consent/partials/info-tab-header.php' ); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Register available addons |
| 184 | * |
| 185 | * @throws Exception |
| 186 | * @since 1.3.0 |
| 187 | */ |
| 188 | private function register_available_addons() { |
| 189 | add_settings_section( |
| 190 | 'available_addons', |
| 191 | '', |
| 192 | array( |
| 193 | $this, |
| 194 | 'header_available_addons', |
| 195 | ), |
| 196 | 'cookiebot-addons' |
| 197 | ); |
| 198 | |
| 199 | /** @var Base_Cookiebot_Addon $addon */ |
| 200 | foreach ( $this->settings_service->get_addons() as $addon ) { |
| 201 | if ( $addon->is_addon_installed() && $addon->is_addon_activated() ) { |
| 202 | add_settings_field( |
| 203 | $addon::OPTION_NAME, |
| 204 | get_view_html( |
| 205 | 'admin/settings/prior-consent/partials/extra-information.php', |
| 206 | array( |
| 207 | 'label' => $addon::ADDON_NAME, |
| 208 | 'extra_information_lines' => $addon->get_extra_information(), |
| 209 | ) |
| 210 | ), |
| 211 | array( |
| 212 | $this, |
| 213 | 'available_addon_callback', |
| 214 | ), |
| 215 | 'cookiebot-addons', |
| 216 | 'available_addons', |
| 217 | array( |
| 218 | 'addon' => $addon, |
| 219 | ) |
| 220 | ); |
| 221 | |
| 222 | register_setting( |
| 223 | 'cookiebot_available_addons', |
| 224 | 'cookiebot_available_addons', |
| 225 | array( |
| 226 | $this, |
| 227 | 'sanitize_cookiebot', |
| 228 | ) |
| 229 | ); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Register jetpack addon - new tab for jetpack specific settings |
| 236 | * |
| 237 | * @throws Exception |
| 238 | * @since 1.3.0 |
| 239 | */ |
| 240 | private function register_jetpack_addon() { |
| 241 | add_settings_section( |
| 242 | 'jetpack_addon', |
| 243 | '', |
| 244 | array( |
| 245 | $this, |
| 246 | 'jetpack_addons_header_callback', |
| 247 | ), |
| 248 | 'cookiebot-addons' |
| 249 | ); |
| 250 | |
| 251 | /** @var Jetpack $addon */ |
| 252 | foreach ( $this->settings_service->get_addons() as $addon ) { |
| 253 | if ( 'Jetpack' === ( new ReflectionClass( $addon ) )->getShortName() ) { |
| 254 | if ( $addon->is_addon_installed() && $addon->is_addon_activated() ) { |
| 255 | foreach ( $addon->get_widgets() as $widget ) { |
| 256 | add_settings_field( |
| 257 | $widget->get_widget_option_name(), |
| 258 | get_view_html( |
| 259 | 'admin/settings/prior-consent/partials/extra-information.php', |
| 260 | array( |
| 261 | 'label' => $widget->get_label(), |
| 262 | 'extra_information_lines' => $widget->get_extra_information(), |
| 263 | ) |
| 264 | ), |
| 265 | array( |
| 266 | $this, |
| 267 | 'jetpack_addon_callback', |
| 268 | ), |
| 269 | 'cookiebot-addons', |
| 270 | 'jetpack_addon', |
| 271 | array( |
| 272 | 'widget' => $widget, |
| 273 | 'addon' => $addon, |
| 274 | ) |
| 275 | ); |
| 276 | |
| 277 | register_setting( 'cookiebot_jetpack_addon', 'cookiebot_jetpack_addon' ); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Registers unavailabe addons |
| 286 | * |
| 287 | * @throws Exception |
| 288 | * @version 2.1.3 |
| 289 | * @since 1.3.0 |
| 290 | */ |
| 291 | private function register_unavailable_addons() { |
| 292 | add_settings_section( |
| 293 | 'unavailable_addons', |
| 294 | '', |
| 295 | array( |
| 296 | $this, |
| 297 | 'unavailable_addons_header_callback', |
| 298 | ), |
| 299 | 'cookiebot-addons' |
| 300 | ); |
| 301 | |
| 302 | $addons = $this->settings_service->get_addons(); |
| 303 | |
| 304 | /** @var Base_Cookiebot_Addon $addon */ |
| 305 | foreach ( $addons as $addon ) { |
| 306 | if ( ! $addon->is_addon_installed() || ! $addon->is_addon_activated() ) { |
| 307 | // not installed plugins |
| 308 | add_settings_field( |
| 309 | $addon::ADDON_NAME, |
| 310 | get_view_html( |
| 311 | 'admin/settings/prior-consent/partials/extra-information.php', |
| 312 | array( |
| 313 | 'label' => $addon::ADDON_NAME, |
| 314 | 'extra_information_lines' => $addon->get_extra_information(), |
| 315 | ) |
| 316 | ), |
| 317 | array( |
| 318 | $this, |
| 319 | 'unavailable_addon_settings_field_callback', |
| 320 | ), |
| 321 | 'cookiebot-addons', |
| 322 | 'unavailable_addons', |
| 323 | array( 'addon' => $addon ) |
| 324 | ); |
| 325 | register_setting( $addon::OPTION_NAME, 'cookiebot_unavailable_addons' ); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Jetpack tab - header |
| 332 | * |
| 333 | * @throws InvalidArgumentException |
| 334 | * @since 1.3.0 |
| 335 | */ |
| 336 | public function jetpack_addons_header_callback() { |
| 337 | include_view( 'admin/settings/prior-consent/jetpack-widgets/tab-header.php' ); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Jetpack tab - widget callback |
| 342 | * |
| 343 | * @param $args array Information about the widget addon and the option |
| 344 | * |
| 345 | * @throws InvalidArgumentException |
| 346 | * @since 1.3.0 |
| 347 | */ |
| 348 | public function jetpack_addon_callback( $args ) { |
| 349 | $widget = isset( $args['widget'] ) ? $args['widget'] : null; |
| 350 | $addon = isset( $args['addon'] ) ? $args['addon'] : null; |
| 351 | |
| 352 | if ( ! is_a( $widget, Base_Jetpack_Widget::class ) ) { |
| 353 | throw new InvalidArgumentException(); |
| 354 | } |
| 355 | |
| 356 | if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) { |
| 357 | throw new InvalidArgumentException(); |
| 358 | } |
| 359 | |
| 360 | $widget_is_enabled = $widget->is_widget_enabled(); |
| 361 | $widget_placeholder_is_enabled = $widget->is_widget_placeholder_enabled(); |
| 362 | $widget_default_placeholder = $widget->get_widget_default_placeholder(); |
| 363 | $widget_option_name = $widget->get_widget_option_name(); |
| 364 | $widget_placeholders_array = $widget->get_widget_placeholders(); |
| 365 | $widget_placeholders_array_keys = array_keys( $widget_placeholders_array ); |
| 366 | $first_placeholder_language = isset( $widget_placeholders_array_keys[0] ) |
| 367 | ? $widget_placeholders_array_keys[0] |
| 368 | : null; |
| 369 | $site_default_languages_dropdown_html = 'cookiebot_jetpack_addon[' . $widget_option_name . '][placeholder][languages][site-default]'; |
| 370 | $widget_placeholders = array_map( |
| 371 | function( $language, $placeholder ) use ( $widget_option_name, $widget_placeholders_array, $first_placeholder_language ) { |
| 372 | $removable = $first_placeholder_language !== $language; |
| 373 | $option_name = 'cookiebot_jetpack_addon[' . $widget_option_name . '][placeholder][languages][' . $language . ']'; |
| 374 | $languages_dropdown_html = cookiebot_addons_get_dropdown_languages( |
| 375 | 'placeholder_select_language', |
| 376 | $option_name, |
| 377 | $language |
| 378 | ); |
| 379 | return array( |
| 380 | 'name' => $option_name, |
| 381 | 'removable' => $removable, |
| 382 | 'language' => $language, |
| 383 | 'placeholder' => $placeholder, |
| 384 | 'languages_dropdown_html' => $languages_dropdown_html, |
| 385 | ); |
| 386 | }, |
| 387 | array_keys( $widget_placeholders_array ), |
| 388 | array_values( $widget_placeholders_array ) |
| 389 | ); |
| 390 | $placeholder_helper = $addon->get_placeholder_helper(); |
| 391 | $placeholders_html = $widget->widget_has_placeholder() |
| 392 | ? get_view_html( |
| 393 | 'admin/settings/prior-consent/partials/placeholder-submitboxes.php', |
| 394 | array( |
| 395 | 'placeholders' => $widget_placeholders, |
| 396 | 'placeholder_helper' => $placeholder_helper, |
| 397 | ) |
| 398 | ) |
| 399 | : get_view_html( |
| 400 | 'admin/settings/prior-consent/partials/placeholder-submitbox-default.php', |
| 401 | array( |
| 402 | 'site_default_languages_dropdown_html' => $site_default_languages_dropdown_html, |
| 403 | 'name' => 'cookiebot_jetpack_addon[' . $widget_option_name . '][placeholder][languages][site-default]', |
| 404 | 'default_placeholder' => $widget_default_placeholder, |
| 405 | 'placeholder_helper' => $placeholder_helper, |
| 406 | ) |
| 407 | ); |
| 408 | |
| 409 | $view_args = array( |
| 410 | 'widget_option_name' => $widget_option_name, |
| 411 | 'widget_is_enabled' => $widget_is_enabled, |
| 412 | 'widget_cookie_types' => $widget->get_widget_cookie_types(), |
| 413 | 'widget_placeholder_is_enabled' => $widget_placeholder_is_enabled, |
| 414 | 'placeholders_html' => $placeholders_html, |
| 415 | ); |
| 416 | |
| 417 | include_view( 'admin/settings/prior-consent/jetpack-widgets/tab.php', $view_args ); |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Returns header for installed plugins |
| 422 | * |
| 423 | * @since 1.3.0 |
| 424 | */ |
| 425 | public function header_available_addons() { |
| 426 | include_view( 'admin/settings/prior-consent/available-addons/tab-header.php' ); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Available addon callback: |
| 431 | * - checkbox to enable |
| 432 | * - select field for cookie type |
| 433 | * |
| 434 | * @param $args |
| 435 | * |
| 436 | * @throws InvalidArgumentException |
| 437 | * @since 1.3.0 |
| 438 | */ |
| 439 | public function available_addon_callback( $args ) { |
| 440 | $addon = isset( $args['addon'] ) ? $args['addon'] : null; |
| 441 | |
| 442 | if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) { |
| 443 | throw new InvalidArgumentException(); |
| 444 | } |
| 445 | |
| 446 | $site_default_languages_dropdown_html = 'cookiebot_available_addons[' . $addon::OPTION_NAME . '][placeholder][languages][site-default]'; |
| 447 | $addon_placeholders_array = $addon->get_placeholders(); |
| 448 | $addon_placeholders_array_keys = array_keys( $addon_placeholders_array ); |
| 449 | $first_placeholder_language = isset( $addon_placeholders_array_keys[0] ) |
| 450 | ? $addon_placeholders_array_keys[0] |
| 451 | : null; |
| 452 | $addon_placeholders = array_map( |
| 453 | function( $language, $placeholder ) use ( $addon, $addon_placeholders_array, $first_placeholder_language ) { |
| 454 | $removable = $first_placeholder_language !== $language; |
| 455 | $option_name = 'cookiebot_available_addons[' . $addon::OPTION_NAME . '][placeholder][languages][' . $language . ']'; |
| 456 | $languages_dropdown_html = cookiebot_addons_get_dropdown_languages( |
| 457 | 'placeholder_select_language', |
| 458 | $option_name, |
| 459 | $language |
| 460 | ); |
| 461 | return array( |
| 462 | 'name' => $option_name, |
| 463 | 'removable' => $removable, |
| 464 | 'language' => $language, |
| 465 | 'placeholder' => $placeholder, |
| 466 | 'languages_dropdown_html' => $languages_dropdown_html, |
| 467 | ); |
| 468 | }, |
| 469 | $addon_placeholders_array_keys, |
| 470 | $addon_placeholders_array |
| 471 | ); |
| 472 | $placeholder_helper = $addon->get_placeholder_helper(); |
| 473 | $addon_extra_options_html = $addon->get_extra_addon_options_html(); |
| 474 | $placeholders_html = $addon->has_placeholder() |
| 475 | ? get_view_html( |
| 476 | 'admin/settings/prior-consent/partials/placeholder-submitboxes.php', |
| 477 | array( |
| 478 | 'placeholders' => $addon_placeholders, |
| 479 | 'placeholder_helper' => $placeholder_helper, |
| 480 | ) |
| 481 | ) |
| 482 | : get_view_html( |
| 483 | 'admin/settings/prior-consent/partials/placeholder-submitbox-default.php', |
| 484 | array( |
| 485 | 'site_default_languages_dropdown_html' => $site_default_languages_dropdown_html, |
| 486 | 'name' => 'cookiebot_available_addons[' . $addon::OPTION_NAME . '][placeholder][languages][site-default]', |
| 487 | 'default_placeholder' => $addon::DEFAULT_PLACEHOLDER_CONTENT, |
| 488 | 'placeholder_helper' => $placeholder_helper, |
| 489 | ) |
| 490 | ); |
| 491 | |
| 492 | $view_args = array( |
| 493 | 'addon_option_name' => $addon::OPTION_NAME, |
| 494 | 'addon_is_enabled' => $addon->is_addon_enabled(), |
| 495 | 'addon_cookie_types' => $addon->get_cookie_types(), |
| 496 | 'addon_placeholder_is_enabled' => $addon->is_placeholder_enabled(), |
| 497 | 'placeholders_html' => $placeholders_html, |
| 498 | 'addon_extra_options_html' => $addon_extra_options_html, |
| 499 | ); |
| 500 | |
| 501 | include_view( 'admin/settings/prior-consent/available-addons/tab.php', $view_args ); |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Returns header for unavailable plugins |
| 506 | * |
| 507 | * @throws InvalidArgumentException |
| 508 | * @since 1.3.0 |
| 509 | */ |
| 510 | public function unavailable_addons_header_callback() { |
| 511 | include_view( 'admin/settings/prior-consent/unavailable-addons/tab-header.php' ); |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * @param $args |
| 516 | * |
| 517 | * @throws InvalidArgumentException |
| 518 | */ |
| 519 | public function unavailable_addon_settings_field_callback( $args ) { |
| 520 | $addon = $args['addon']; |
| 521 | |
| 522 | if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) { |
| 523 | throw new InvalidArgumentException(); |
| 524 | } |
| 525 | |
| 526 | $message = ''; |
| 527 | if ( ! $addon->is_addon_installed() ) { |
| 528 | if ( is_a( $addon, Base_Cookiebot_Plugin_Addon::class ) ) { |
| 529 | $message = __( 'The plugin is not installed.', 'cookiebot' ); |
| 530 | } |
| 531 | if ( is_a( $addon, Base_Cookiebot_Theme_Addon::class ) ) { |
| 532 | $message = __( 'The theme is not installed.', 'cookiebot' ); |
| 533 | } |
| 534 | } elseif ( ! $addon->is_addon_activated() ) { |
| 535 | if ( is_a( $addon, Base_Cookiebot_Plugin_Addon::class ) ) { |
| 536 | $message = __( 'The plugin is not activated.', 'cookiebot' ); |
| 537 | } |
| 538 | if ( is_a( $addon, Base_Cookiebot_Theme_Addon::class ) ) { |
| 539 | $message = __( 'The theme is not activated.', 'cookiebot' ); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | $view_args = array( |
| 544 | 'message' => $message, |
| 545 | ); |
| 546 | include_view( 'admin/settings/prior-consent/unavailable-addons/field.php', $view_args ); |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Build up settings page |
| 551 | * |
| 552 | * @throws InvalidArgumentException |
| 553 | * @since 1.3.0 |
| 554 | */ |
| 555 | public function setting_page() { |
| 556 | $addons_info_tab = new Settings_Page_Tab( |
| 557 | 'addons_info', |
| 558 | esc_html__( 'Info', 'cookiebot' ), |
| 559 | 'info_addons', |
| 560 | 'cookiebot-addons', |
| 561 | false |
| 562 | ); |
| 563 | $available_addons_tab = new Settings_Page_Tab( |
| 564 | 'available_addons', |
| 565 | esc_html__( 'Available Add-ons', 'cookiebot' ), |
| 566 | 'cookiebot_available_addons', |
| 567 | 'cookiebot-addons' |
| 568 | ); |
| 569 | $unavailable_addons_tab = new Settings_Page_Tab( |
| 570 | 'unavailable_addons', |
| 571 | esc_html__( 'Unavailable Add-ons', 'cookiebot' ), |
| 572 | 'cookiebot_not_installed_options', |
| 573 | 'cookiebot-addons', |
| 574 | false |
| 575 | ); |
| 576 | $settings_page_tabs = array( |
| 577 | $addons_info_tab, |
| 578 | $available_addons_tab, |
| 579 | $unavailable_addons_tab, |
| 580 | ); |
| 581 | if ( is_plugin_active( Jetpack::PLUGIN_FILE_PATH ) ) { |
| 582 | $settings_page_tabs[] = new Settings_Page_Tab( |
| 583 | 'jetpack', |
| 584 | esc_html__( 'Jetpack', 'cookiebot' ), |
| 585 | 'cookiebot_jetpack_addon', |
| 586 | 'cookiebot-addons' |
| 587 | ); |
| 588 | } |
| 589 | $active_tab = array_reduce( |
| 590 | $settings_page_tabs, |
| 591 | function( $active_tab, Settings_Page_Tab $settings_page_tab ) { |
| 592 | if ( ! is_null( $active_tab ) ) { |
| 593 | return $active_tab; |
| 594 | } |
| 595 | if ( $settings_page_tab->is_active() ) { |
| 596 | return $settings_page_tab; |
| 597 | } |
| 598 | return null; |
| 599 | }, |
| 600 | null |
| 601 | ); |
| 602 | if ( ! $active_tab ) { |
| 603 | $addons_info_tab->set_is_active( true ); |
| 604 | $active_tab = $addons_info_tab; |
| 605 | } |
| 606 | $view_args = array( |
| 607 | 'settings_page_tabs' => $settings_page_tabs, |
| 608 | 'active_tab' => $active_tab, |
| 609 | ); |
| 610 | include_view( 'admin/settings/prior-consent/page.php', $view_args ); |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Post action hook after enabling the addon on the settings page. |
| 615 | * |
| 616 | * @param $old_value |
| 617 | * @param $value |
| 618 | * @param $option_name |
| 619 | * |
| 620 | * @throws Exception |
| 621 | * @since 2.2.0 |
| 622 | */ |
| 623 | public function post_hook_available_addons_update_option( $old_value, $value, $option_name ) { |
| 624 | if ( is_array( $value ) ) { |
| 625 | foreach ( $value as $addon_option_name => $addon_settings ) { |
| 626 | if ( isset( $addon_settings['enabled'] ) ) { |
| 627 | $this->settings_service->post_hook_after_enabling_addon_on_settings_page( $addon_option_name ); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 |