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