PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.0.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.0.0
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 / widgets / Cookiebot_Declaration_Widget.php
cookiebot / src / widgets Last commit date
Cookiebot_Declaration_Widget.php 4 years ago Dashboard_Widget_Cookiebot_Status.php 4 years ago
Cookiebot_Declaration_Widget.php
93 lines
1 <?php
2
3 namespace cybot\cookiebot\widgets;
4
5 use cybot\cookiebot\lib\Supported_Languages;
6 use InvalidArgumentException;
7 use WP_Widget;
8 use cybot\cookiebot\lib\Cookiebot_WP;
9 use function cybot\cookiebot\lib\include_view;
10
11 class Cookiebot_Declaration_Widget extends WP_Widget {
12
13 // Main constructor
14 public function __construct() {
15 parent::__construct(
16 'cookiebot_declaration_widget',
17 esc_html__( 'Cookiebot - Cookie Declaration', 'cookiebot' ),
18 array(
19 'customize_selective_refresh' => true,
20 )
21 );
22 }
23
24 // The widget form (for the backend )
25
26 /**
27 * @throws InvalidArgumentException
28 */
29 public function form( $instance ) {
30 $defaults = array(
31 'lang' => '',
32 'title' => '',
33 );
34 $fixed_args = array(
35 'title_field_id' => $this->get_field_id( 'title' ),
36 'title_field_name' => $this->get_field_name( 'title' ),
37 'lang_field_id' => $this->get_field_id( 'lang' ),
38 'lang_field_name' => $this->get_field_name( 'lang' ),
39 'supported_languages' => Supported_Languages::get(),
40 );
41 $view_args = wp_parse_args( (array) $instance, array_merge( $defaults, $fixed_args ) );
42 include_view( 'admin/widgets/cookiebot-declaration-widget-form.php', $view_args );
43 }
44
45 // Update widget settings
46 public function update( $new_instance, $old_instance ) {
47 $instance = $old_instance;
48 $instance['lang'] = isset( $new_instance['lang'] ) ? wp_strip_all_tags( $new_instance['lang'] ) : '';
49 $instance['title'] = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
50 return $instance;
51 }
52
53 /**
54 * Display the widget
55 * @throws InvalidArgumentException
56 */
57 public function widget( $args, $instance ) {
58 $before_widget_html = isset( $args['before_widget'] ) && is_string( $args['before_widget'] )
59 ? $args['before_widget']
60 : '';
61 $after_widget_html = isset( $args['after_widget'] ) && is_string( $args['after_widget'] )
62 ? $args['after_widget']
63 : '';
64 $has_before_title_html = isset( $args['before_title'] ) && is_string( $args['before_title'] );
65 $has_after_title_html = isset( $args['after_title'] ) && is_string( $args['after_title'] );
66 if ( $has_before_title_html && $has_after_title_html ) {
67 $before_title_html = $args['before_title'];
68 $after_title_html = $args['after_title'];
69 } else {
70 $before_title_html = '<h2>';
71 $after_title_html = '</h2>';
72 }
73 $has_widget_title = isset( $instance['title'] ) && is_string( $instance['title'] );
74 $widget_title_html = $has_widget_title
75 ? $before_title_html . $instance['title'] . $after_title_html
76 : '';
77 $tag_attribute_html = get_site_option( 'cookiebot-script-tag-cd-attribute', 'custom' );
78 if ( ! is_multisite() || $tag_attribute_html === 'custom' ) {
79 $tag_attribute_html = get_option( 'cookiebot-script-tag-cd-attribute', 'async' );
80 }
81 $view_args = array(
82 'cookie_declaration_script_url' => 'https://consent.cookiebot.com/' . Cookiebot_WP::get_cbid() . '/cd.js',
83 'culture' => isset( $lang ) && is_string( $lang ) ? $lang : null,
84 'before_widget_html' => $before_widget_html,
85 'after_widget_html' => $after_widget_html,
86 'widget_title_html' => $widget_title_html,
87 'tag_attribute_html' => $tag_attribute_html,
88 );
89 include_view( 'frontend/widgets/cookiebot-declaration-widget.php', $view_args );
90 }
91
92 }
93