PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.3.3
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.3.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 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / src / addons / config / Settings_Config.php
cookiebot / src / addons / config Last commit date
Settings_Config.php 2 years ago
Settings_Config.php
761 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\Consent_API_Helper;
11 use cybot\cookiebot\lib\Settings_Page_Tab;
12 use cybot\cookiebot\lib\Settings_Service_Interface;
13 use cybot\cookiebot\lib\Cookiebot_WP;
14 use Exception;
15 use InvalidArgumentException;
16 use ReflectionClass;
17 use function cybot\cookiebot\lib\asset_url;
18 use function cybot\cookiebot\lib\cookiebot_addons_get_dropdown_languages;
19 use function cybot\cookiebot\lib\get_view_html;
20 use function cybot\cookiebot\lib\include_view;
21
22 class Settings_Config {
23 /**
24 * @var Settings_Service_Interface
25 */
26 protected $settings_service;
27
28 const ADMIN_SLUG = 'cookiebot-addons';
29 const LANGUAGE_DROPDOWN_OPTION_REPLACE = '%optionname%';
30 const JETPACK_DEFAULT_LANGUAGE_DROPDOWN = 'cookiebot_jetpack_addon[%optionname%][placeholder][languages][site-default]';
31 const ADDONS_DEFAULT_LANGUAGE_DROPDOWN = 'cookiebot_available_addons[%optionname%][placeholder][languages][site-default]';
32 // Templates
33 const INFO_HEADER_TEMPLATE = 'admin/settings/prior-consent/partials/info-tab-header.php';
34 const EXTRA_INFO_TEMPLATE = 'admin/settings/prior-consent/partials/extra-information.php';
35 const JETPACK_TAB_HEADER_TEMPLATE = 'admin/settings/prior-consent/jetpack-widgets/tab-header.php';
36 const JETPACK_WIDGET_TAB_TEMPLATE = 'admin/settings/prior-consent/jetpack-widgets/tab.php';
37 const PLACEHOLDER_TEMPLATE = 'admin/settings/prior-consent/partials/placeholder-submitboxes.php';
38 const DEFAULT_PLACEHOLDER_TEMPLATE = 'admin/settings/prior-consent/partials/placeholder-submitbox-default.php';
39 const AVAILABLE_TAB_HEADER_TEMPLATE = 'admin/settings/prior-consent/available-addons/tab-header.php';
40 const AVAILABLE_ADDONS_TAB_TEMPLATE = 'admin/settings/prior-consent/available-addons/tab.php';
41 const UNAVAILABLE_TAB_HEADER_TEMPLATE = 'admin/settings/prior-consent/unavailable-addons/tab-header.php';
42 const UNAVAILABLE_ADDONS_TAB_TEMPLATE = 'admin/settings/prior-consent/unavailable-addons/field.php';
43 const CONSENT_API_TAB_TEMPLATE = 'admin/settings/prior-consent/consent-api/tab.php';
44 // Other
45 const INFO_ICON_ASSET_URL = 'img/icons/info.svg';
46
47 /**
48 * Settings_Config constructor.
49 *
50 * @param Settings_Service_Interface $settings_service
51 *
52 * @since 1.3.0
53 */
54 public function __construct( Settings_Service_Interface $settings_service ) {
55 $this->settings_service = $settings_service;
56 }
57
58 /**
59 * Load data for settings page
60 *
61 * @since 1.3.0
62 */
63 public function load() {
64 add_action( 'admin_menu', array( $this, 'add_submenu' ), 2 );
65 add_action( 'admin_init', array( $this, 'register_settings' ) );
66 add_action( 'admin_enqueue_scripts', array( $this, 'add_wp_admin_style_script' ) );
67 add_action(
68 'update_option_cookiebot_available_addons',
69 array(
70 $this,
71 'post_hook_available_addons_update_option',
72 ),
73 10,
74 3
75 );
76 }
77
78 /**
79 * Registers submenu in options menu.
80 *
81 * @since 1.3.0
82 */
83 public function add_submenu() {
84 add_submenu_page(
85 'cookiebot',
86 esc_html__( 'Plugins', 'cookiebot' ),
87 esc_html__( 'Plugins', 'cookiebot' ),
88 'manage_options',
89 'cookiebot-addons',
90 array(
91 $this,
92 'setting_page',
93 ),
94 2
95 );
96 }
97
98 /**
99 * Load css styling to the settings page
100 *
101 * @throws InvalidArgumentException
102 * @since 1.3.0
103 */
104 public function add_wp_admin_style_script( $hook ) {
105 if ( $hook !== 'cookiebot_page_cookiebot-addons' ) {
106 return;
107 }
108
109 wp_enqueue_script(
110 'cookiebot_tiptip_js',
111 asset_url( 'js/backend/jquery.tipTip.js' ),
112 array( 'jquery' ),
113 '1.8',
114 true
115 );
116 wp_enqueue_script(
117 'cookiebot_addons_custom_js',
118 asset_url( 'js/backend/prior-consent-settings.js' ),
119 array( 'jquery' ),
120 '1.8',
121 true
122 );
123 wp_localize_script(
124 'cookiebot_addons_custom_js',
125 'php',
126 array( 'remove_link' => ' <a href="" class="submitdelete deletion">' . esc_html__( 'Remove language', 'cookiebot' ) . '</a>' )
127 );
128 wp_enqueue_style(
129 'cookiebot_addons_custom_css',
130 asset_url( 'css/backend/addons_page.css' ),
131 null,
132 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
133 );
134 wp_enqueue_style(
135 'cookiebot_admin_css',
136 asset_url( 'css/backend/cookiebot_admin_main.css' ),
137 null,
138 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
139 );
140 }
141
142 /**
143 * Registers addons for settings page.
144 *
145 * @throws Exception
146 * @since 1.3.0
147 */
148 public function register_settings() {
149 global $pagenow;
150
151 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
152 if ( ( isset( $_GET['page'] ) && $_GET['page'] === 'cookiebot-addons' ) || $pagenow === 'options.php' ) {
153 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
154 if ( isset( $_GET['tab'] ) && 'unavailable_addons' === $_GET['tab'] ) {
155 $this->register_unavailable_addons();
156 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
157 } elseif ( isset( $_GET['tab'] ) && 'available_addons' === $_GET['tab'] ) {
158 $this->register_available_addons();
159 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
160 } elseif ( isset( $_GET['tab'] ) && 'jetpack' === $_GET['tab'] ) {
161 $this->register_jetpack_addon();
162 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
163 } elseif ( isset( $_GET['tab'] ) && 'consent_api' === $_GET['tab'] ) {
164 $this->register_consent_api();
165 } else {
166 $this->register_addons_info();
167 }
168
169 if ( $pagenow === 'options.php' ) {
170 $this->register_jetpack_addon();
171 $this->register_available_addons();
172 $this->register_consent_api();
173 }
174 }
175 }
176
177 /**
178 * Register addons info
179 *
180 * @throws Exception
181 * @since 1.3.0
182 */
183 private function register_addons_info() {
184 add_settings_section(
185 'info_addons',
186 '',
187 array(
188 $this,
189 'header_addons_info',
190 ),
191 'cookiebot-addons'
192 );
193 }
194
195 /**
196 * Returns header for info tab
197 *
198 * @since 1.3.0
199 */
200 public function header_addons_info() {
201 include_view( self::INFO_HEADER_TEMPLATE );
202 }
203
204 /**
205 * Register available addons
206 *
207 * @throws Exception
208 * @since 1.3.0
209 */
210 private function register_available_addons() {
211 add_settings_section(
212 'available_addons',
213 '',
214 array(
215 $this,
216 'header_available_addons',
217 ),
218 'cookiebot-addons'
219 );
220
221 /** @var Base_Cookiebot_Addon $addon */
222 foreach ( $this->settings_service->get_addons() as $addon ) {
223 if ( $addon->is_addon_installed() && $addon->is_addon_activated() ) {
224 add_settings_field(
225 $addon::OPTION_NAME,
226 get_view_html(
227 $this::EXTRA_INFO_TEMPLATE,
228 array(
229 'label' => $addon::ADDON_NAME,
230 'extra_information_lines' => $addon->get_extra_information(),
231 )
232 ),
233 array(
234 $this,
235 'available_addon_callback',
236 ),
237 'cookiebot-addons',
238 'available_addons',
239 array(
240 'addon' => $addon,
241 )
242 );
243
244 register_setting(
245 'cookiebot_available_addons',
246 'cookiebot_available_addons',
247 array(
248 $this,
249 'sanitize_cookiebot',
250 )
251 );
252 }
253 }
254 }
255
256 /**
257 * Register jetpack addon - new tab for jetpack specific settings
258 *
259 * @throws Exception
260 * @since 1.3.0
261 */
262 private function register_jetpack_addon() {
263 add_settings_section(
264 'jetpack_addon',
265 '',
266 array(
267 $this,
268 'jetpack_addons_header_callback',
269 ),
270 'cookiebot-addons'
271 );
272
273 /** @var Jetpack $addon */
274 foreach ( $this->settings_service->get_addons() as $addon ) {
275 if ( 'Jetpack' === ( new ReflectionClass( $addon ) )->getShortName() &&
276 $addon->is_addon_installed() && $addon->is_addon_activated() ) {
277 foreach ( $addon->get_widgets() as $widget ) {
278 add_settings_field(
279 $widget->get_widget_option_name(),
280 get_view_html(
281 $this::EXTRA_INFO_TEMPLATE,
282 array(
283 'label' => $widget->get_label(),
284 'extra_information_lines' => $widget->get_extra_information(),
285 )
286 ),
287 array(
288 $this,
289 'jetpack_addon_callback',
290 ),
291 'cookiebot-addons',
292 'jetpack_addon',
293 array(
294 'widget' => $widget,
295 'addon' => $addon,
296 )
297 );
298
299 register_setting( 'cookiebot_jetpack_addon', 'cookiebot_jetpack_addon' );
300 }
301 }
302 }
303 }
304
305 /**
306 * Registers unavailabe addons
307 *
308 * @throws Exception
309 * @version 2.1.3
310 * @since 1.3.0
311 */
312 private function register_unavailable_addons() {
313 add_settings_section(
314 'unavailable_addons',
315 '',
316 array(
317 $this,
318 'unavailable_addons_header_callback',
319 ),
320 'cookiebot-addons'
321 );
322
323 $addons = $this->settings_service->get_addons();
324
325 /** @var Base_Cookiebot_Addon $addon */
326 foreach ( $addons as $addon ) {
327 if ( ! $addon->is_addon_installed() || ! $addon->is_addon_activated() ) {
328 // not installed plugins
329 add_settings_field(
330 $addon::ADDON_NAME,
331 get_view_html(
332 $this::EXTRA_INFO_TEMPLATE,
333 array(
334 'label' => $addon::ADDON_NAME,
335 'extra_information_lines' => $addon->get_extra_information(),
336 )
337 ),
338 array(
339 $this,
340 'unavailable_addon_settings_field_callback',
341 ),
342 'cookiebot-addons',
343 'unavailable_addons',
344 array( 'addon' => $addon )
345 );
346 register_setting( $addon::OPTION_NAME, 'cookiebot_unavailable_addons' );
347 }
348 }
349 }
350
351 /**
352 * Jetpack tab - header
353 *
354 * @throws InvalidArgumentException
355 * @since 1.3.0
356 */
357 public function jetpack_addons_header_callback() {
358 include_view( self::JETPACK_TAB_HEADER_TEMPLATE );
359 }
360
361 /**
362 * Jetpack tab - widget callback
363 *
364 * @param $args array Information about the widget addon and the option
365 *
366 * @throws InvalidArgumentException
367 * @since 1.3.0
368 */
369 public function jetpack_addon_callback( $args ) {
370 $widget = isset( $args['widget'] ) ? $args['widget'] : null;
371 $addon = isset( $args['addon'] ) ? $args['addon'] : null;
372
373 if ( ! is_a( $widget, Base_Jetpack_Widget::class ) ) {
374 throw new InvalidArgumentException();
375 }
376
377 if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) {
378 throw new InvalidArgumentException();
379 }
380
381 $widget_is_enabled = $widget->is_widget_enabled();
382 $widget_placeholder_is_enabled = $widget->is_widget_placeholder_enabled();
383 $widget_default_placeholder = $widget->get_widget_default_placeholder();
384 $widget_option_name = $widget->get_widget_option_name();
385 $widget_placeholders_array = $widget->get_widget_placeholders();
386 $widget_placeholders_array_keys = array_keys( $widget_placeholders_array );
387 $first_placeholder_language = isset( $widget_placeholders_array_keys[0] )
388 ? $widget_placeholders_array_keys[0]
389 : null;
390 $site_default_languages_dropdown_html = cookiebot_addons_get_dropdown_languages(
391 'placeholder_select_language',
392 str_replace(
393 self::LANGUAGE_DROPDOWN_OPTION_REPLACE,
394 $widget_option_name,
395 self::JETPACK_DEFAULT_LANGUAGE_DROPDOWN
396 ),
397 'site-default'
398 );
399 $widget_placeholders = array_map(
400 function (
401 $language,
402 $placeholder
403 ) use (
404 $widget_option_name,
405 $first_placeholder_language
406 ) {
407 $removable = $first_placeholder_language !== $language;
408 $option_name = str_replace(
409 array( self::LANGUAGE_DROPDOWN_OPTION_REPLACE, 'site-default' ),
410 array( $widget_option_name, $language ),
411 self::JETPACK_DEFAULT_LANGUAGE_DROPDOWN
412 );
413 $languages_dropdown_html = cookiebot_addons_get_dropdown_languages(
414 'placeholder_select_language',
415 $option_name,
416 $language
417 );
418 return array(
419 'name' => $option_name,
420 'removable' => $removable,
421 'language' => $language,
422 'placeholder' => $placeholder,
423 'languages_dropdown_html' => $languages_dropdown_html,
424 );
425 },
426 array_keys( $widget_placeholders_array ),
427 array_values( $widget_placeholders_array )
428 );
429 $placeholder_helper = $addon->get_placeholder_helper();
430 $placeholders_html = $widget->widget_has_placeholder()
431 ? get_view_html(
432 self::PLACEHOLDER_TEMPLATE,
433 array(
434 'placeholders' => $widget_placeholders,
435 'placeholder_helper' => $placeholder_helper,
436 'info_icon' => asset_url( self::INFO_ICON_ASSET_URL ),
437 )
438 )
439 : get_view_html(
440 self::DEFAULT_PLACEHOLDER_TEMPLATE,
441 array(
442 'site_default_languages_dropdown_html' => $site_default_languages_dropdown_html,
443 'name' => str_replace(
444 self::LANGUAGE_DROPDOWN_OPTION_REPLACE,
445 $widget_option_name,
446 self::JETPACK_DEFAULT_LANGUAGE_DROPDOWN
447 ),
448 'default_placeholder' => $widget_default_placeholder,
449 'placeholder_helper' => $placeholder_helper,
450 'info_icon' => asset_url( self::INFO_ICON_ASSET_URL ),
451 )
452 );
453
454 $view_args = array(
455 'widget_option_name' => $widget_option_name,
456 'widget_is_enabled' => $widget_is_enabled,
457 'widget_cookie_types' => $widget->get_widget_cookie_types(),
458 'widget_placeholder_is_enabled' => $widget_placeholder_is_enabled,
459 'placeholders_html' => $placeholders_html,
460 );
461
462 include_view( self::JETPACK_WIDGET_TAB_TEMPLATE, $view_args );
463 }
464
465 /**
466 * Returns header for installed plugins
467 *
468 * @since 1.3.0
469 */
470 public function header_available_addons() {
471 include_view( self::AVAILABLE_TAB_HEADER_TEMPLATE );
472 }
473
474 /**
475 * Available addon callback:
476 * - checkbox to enable
477 * - select field for cookie type
478 *
479 * @param $args
480 *
481 * @throws InvalidArgumentException
482 * @since 1.3.0
483 */
484 public function available_addon_callback( $args ) {
485 $addon = isset( $args['addon'] ) ? $args['addon'] : null;
486
487 if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) {
488 throw new InvalidArgumentException();
489 }
490
491 $site_default_languages_dropdown_html = cookiebot_addons_get_dropdown_languages(
492 'placeholder_select_language',
493 str_replace(
494 self::LANGUAGE_DROPDOWN_OPTION_REPLACE,
495 $addon::OPTION_NAME,
496 self::ADDONS_DEFAULT_LANGUAGE_DROPDOWN
497 ),
498 'site-default'
499 );
500 $addon_placeholders_array = $addon->get_placeholders();
501 $addon_placeholders_array_keys = array_keys( $addon_placeholders_array );
502 $first_placeholder_language = isset( $addon_placeholders_array_keys[0] )
503 ? $addon_placeholders_array_keys[0]
504 : null;
505 $addon_placeholders = array_map(
506 function (
507 $language,
508 $placeholder
509 ) use (
510 $addon,
511 $first_placeholder_language
512 ) {
513 $removable = $first_placeholder_language !== $language;
514 $option_name = str_replace(
515 array( self::LANGUAGE_DROPDOWN_OPTION_REPLACE, 'site-default' ),
516 array( $addon::OPTION_NAME, $language ),
517 self::ADDONS_DEFAULT_LANGUAGE_DROPDOWN
518 );
519 $languages_dropdown_html = cookiebot_addons_get_dropdown_languages(
520 'placeholder_select_language',
521 $option_name,
522 $language
523 );
524 return array(
525 'name' => $option_name,
526 'removable' => $removable,
527 'language' => $language,
528 'placeholder' => $placeholder,
529 'languages_dropdown_html' => $languages_dropdown_html,
530 );
531 },
532 $addon_placeholders_array_keys,
533 $addon_placeholders_array
534 );
535 $placeholder_helper = $addon->get_placeholder_helper();
536 $addon_extra_options_html = $addon->get_extra_addon_options_html();
537 $placeholders_html = $addon->has_placeholder()
538 ? get_view_html(
539 self::PLACEHOLDER_TEMPLATE,
540 array(
541 'placeholders' => $addon_placeholders,
542 'placeholder_helper' => $placeholder_helper,
543 'info_icon' => asset_url( self::INFO_ICON_ASSET_URL ),
544 )
545 )
546 : get_view_html(
547 self::DEFAULT_PLACEHOLDER_TEMPLATE,
548 array(
549 'site_default_languages_dropdown_html' => $site_default_languages_dropdown_html,
550 'name' => str_replace(
551 self::LANGUAGE_DROPDOWN_OPTION_REPLACE,
552 $addon::OPTION_NAME,
553 self::ADDONS_DEFAULT_LANGUAGE_DROPDOWN
554 ),
555 'default_placeholder' => $addon::DEFAULT_PLACEHOLDER_CONTENT,
556 'placeholder_helper' => $placeholder_helper,
557 'info_icon' => asset_url( self::INFO_ICON_ASSET_URL ),
558 )
559 );
560
561 $view_args = array(
562 'addon_option_name' => $addon::OPTION_NAME,
563 'addon_is_enabled' => $addon->is_addon_enabled(),
564 'addon_cookie_types' => $addon->get_cookie_types(),
565 'addon_placeholder_is_enabled' => $addon->is_placeholder_enabled(),
566 'placeholders_html' => $placeholders_html,
567 'addon_extra_options_html' => $addon_extra_options_html,
568 );
569
570 include_view( self::AVAILABLE_ADDONS_TAB_TEMPLATE, $view_args );
571 }
572
573 /**
574 * Returns header for unavailable plugins
575 *
576 * @throws InvalidArgumentException
577 * @since 1.3.0
578 */
579 public function unavailable_addons_header_callback() {
580 include_view( self::UNAVAILABLE_TAB_HEADER_TEMPLATE );
581 }
582
583 /**
584 * @param $args
585 *
586 * @throws InvalidArgumentException
587 */
588 public function unavailable_addon_settings_field_callback( $args ) {
589 $addon = $args['addon'];
590
591 if ( ! is_a( $addon, Base_Cookiebot_Addon::class ) ) {
592 throw new InvalidArgumentException();
593 }
594
595 $message = '';
596 if ( ! $addon->is_addon_installed() ) {
597 if ( is_a( $addon, Base_Cookiebot_Plugin_Addon::class ) ) {
598 $message = __( 'The plugin is not installed.', 'cookiebot' );
599 }
600 if ( is_a( $addon, Base_Cookiebot_Theme_Addon::class ) ) {
601 $message = __( 'The theme is not installed.', 'cookiebot' );
602 }
603 } elseif ( ! $addon->is_addon_activated() ) {
604 if ( is_a( $addon, Base_Cookiebot_Plugin_Addon::class ) ) {
605 $message = __( 'The plugin is not activated.', 'cookiebot' );
606 }
607 if ( is_a( $addon, Base_Cookiebot_Theme_Addon::class ) ) {
608 $message = __( 'The theme is not activated.', 'cookiebot' );
609 }
610 }
611
612 $view_args = array(
613 'message' => $message,
614 );
615 include_view( self::UNAVAILABLE_ADDONS_TAB_TEMPLATE, $view_args );
616 }
617
618 /**
619 * Adds WP Consent API Section
620 *
621 * @version 4.2.14
622 * @since 4.2.14
623 */
624 private function register_consent_api() {
625 wp_enqueue_style(
626 'cookiebot-consent-mapping-table',
627 asset_url( 'css/backend/consent_mapping_table.css' ),
628 null,
629 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
630 );
631
632 wp_enqueue_script(
633 'cookiebot_consent_mapping_js',
634 asset_url( 'js/backend/consent-mapping.js' ),
635 array( 'jquery' ),
636 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
637 true
638 );
639
640 add_settings_section(
641 'consent_api',
642 '',
643 array(
644 $this,
645 'consent_api_callback',
646 ),
647 'cookiebot-addons'
648 );
649
650 register_setting( 'cookiebot-consent-mapping', 'cookiebot-consent-mapping' );
651 }
652
653 /**
654 * Consent API tab callback
655 *
656 * @since 4.2.14
657 */
658 public function consent_api_callback() {
659 $consent_api_helper = new Consent_API_Helper();
660 $view_args = array(
661 'is_wp_consent_api_active' => $consent_api_helper->is_wp_consent_api_active(),
662 'm_default' => $consent_api_helper->get_default_wp_consent_api_mapping(),
663 'm' => $consent_api_helper->get_wp_consent_api_mapping(),
664 );
665
666 include_view( self::CONSENT_API_TAB_TEMPLATE, $view_args );
667 }
668
669 /**
670 * Build up settings page
671 *
672 * @throws InvalidArgumentException
673 * @since 1.3.0
674 */
675 public function setting_page() {
676 $addons_info_tab = new Settings_Page_Tab(
677 'addons_info',
678 esc_html__( 'Info', 'cookiebot' ),
679 'info_addons',
680 'cookiebot-addons',
681 false
682 );
683 $available_addons_tab = new Settings_Page_Tab(
684 'available_addons',
685 esc_html__( 'Available Add-ons', 'cookiebot' ),
686 'cookiebot_available_addons',
687 'cookiebot-addons'
688 );
689 $unavailable_addons_tab = new Settings_Page_Tab(
690 'unavailable_addons',
691 esc_html__( 'Unavailable Add-ons', 'cookiebot' ),
692 'cookiebot_not_installed_options',
693 'cookiebot-addons',
694 false
695 );
696 $settings_page_tabs = array(
697 $addons_info_tab,
698 $available_addons_tab,
699 $unavailable_addons_tab,
700 );
701 if ( is_plugin_active( Jetpack::PLUGIN_FILE_PATH ) ) {
702 $settings_page_tabs[] = new Settings_Page_Tab(
703 'jetpack',
704 esc_html__( 'Jetpack', 'cookiebot' ),
705 'cookiebot_jetpack_addon',
706 'cookiebot-addons'
707 );
708 }
709 if ( is_plugin_active( 'wp-consent-api/wp-consent-api.php' ) ) {
710 $settings_page_tabs[] = new Settings_Page_Tab(
711 'consent_api',
712 esc_html__( 'WP Consent API', 'cookiebot' ),
713 'cookiebot-consent-mapping',
714 'cookiebot-addons'
715 );
716 }
717 $active_tab = array_reduce(
718 $settings_page_tabs,
719 function ( $active_tab, Settings_Page_Tab $settings_page_tab ) {
720 if ( ! is_null( $active_tab ) ) {
721 return $active_tab;
722 }
723 if ( $settings_page_tab->is_active() ) {
724 return $settings_page_tab;
725 }
726 return null;
727 },
728 null
729 );
730 if ( ! $active_tab ) {
731 $addons_info_tab->set_is_active( true );
732 $active_tab = $addons_info_tab;
733 }
734 $view_args = array(
735 'settings_page_tabs' => $settings_page_tabs,
736 'active_tab' => $active_tab,
737 );
738 include_view( 'admin/settings/prior-consent/page.php', $view_args );
739 }
740
741 /**
742 * Post action hook after enabling the addon on the settings page.
743 *
744 * @param $old_value
745 * @param $value
746 * @param $option_name
747 *
748 * @throws Exception
749 * @since 2.2.0
750 */
751 public function post_hook_available_addons_update_option( $value ) {
752 if ( is_array( $value ) ) {
753 foreach ( $value as $addon_option_name => $addon_settings ) {
754 if ( isset( $addon_settings['enabled'] ) ) {
755 $this->settings_service->post_hook_after_enabling_addon_on_settings_page( $addon_option_name );
756 }
757 }
758 }
759 }
760 }
761