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 / widgets / cookiebot-declaration-widget.php
cookiebot / widgets Last commit date
cookiebot-declaration-widget.php 4 years ago
cookiebot-declaration-widget.php
125 lines
1 <?php
2
3 // The widget class for Cookiebot D
4 class Cookiebot_Declaration_Widget extends WP_Widget {
5
6 // Main constructor
7 public function __construct() {
8 parent::__construct(
9 'cookiebot_declaration_widget',
10 esc_html__( 'Cookiebot - Cookie Declaration', 'cookiebot' ),
11 array(
12 'customize_selective_refresh' => true,
13 )
14 );
15 }
16
17 /**
18 * Outputs the settings update form.
19 *
20 * @since 2.8.0
21 *
22 * @param array $instance Current settings.
23 * @return string Default return is 'noform'.
24 */
25 public function form( $instance ) {
26 $lang = isset( $instance['lang'] ) ? $instance['lang'] : '';
27 $title = isset( $instance['title'] ) ? $instance['title'] : '';
28 ?>
29 <p>
30 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'Cookiebot' ); ?></label>
31 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
32 </p>
33 <p>
34 <label for="<?php echo esc_attr( $this->get_field_id( 'lang' ) ); ?>"><?php esc_html_e( 'Language', 'cookiebot' ); ?></label>
35 <select name="<?php echo esc_attr( $this->get_field_name( 'lang' ) ); ?>"
36 id="<?php echo esc_attr( $this->get_field_id( 'lang' ) ); ?>"
37 class="widefat">
38 <option value=""><?php echo esc_html__( '- Default -', 'cookiebot' ); ?></option>
39 <?php
40 $options = Cookiebot_WP::get_supported_languages();
41 foreach ( $options as $key => $name ) {
42 ?>
43 <option value="<?php echo esc_attr( $key ); ?>"
44 id="<?php echo esc_attr( $key ); ?>"
45 class="value"
46 <?php selected( $lang, $key, false, true ); ?>
47 ><?php echo esc_html( $name ); ?></option>
48 <?php
49 }
50 ?>
51 </select>
52 </p>
53 <?php
54
55 // the base function expects a string to be returned
56 return '';
57 }
58
59 // Update widget settings
60 public function update( $new_instance, $old_instance ) {
61 $instance = $old_instance;
62 $instance['lang'] = isset( $new_instance['lang'] ) ? wp_strip_all_tags( $new_instance['lang'] ) : '';
63 $instance['title'] = isset( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
64 return $instance;
65 }
66
67 // Display the widget
68
69 /**
70 * Echoes the widget content.
71 *
72 * Subclasses should override this function to generate their widget code.
73 *
74 * @since 2.8.0
75 *
76 * @param array $args Display arguments including 'before_title', 'after_title',
77 * 'before_widget', and 'after_widget'.
78 * @param array $instance The settings for the particular instance of the widget.
79 */
80 public function widget( $args, $instance ) {
81 $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
82 $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
83 $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
84 $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
85 $lang = isset( $instance['lang'] ) ? $instance['lang'] : '';
86 $title = isset( $instance['title'] ) ? $instance['title'] : '';
87
88 // WordPress core before_widget hook
89 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
90 echo $before_widget;
91
92 echo '<div class="widget-text wp_widget_plugin_box cookiebot_cookie_declaration">';
93
94 // Display widget title if defined
95 if ( $title ) {
96 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
97 echo $before_title . esc_html( $title ) . $after_title;
98 }
99
100 $cbid = Cookiebot_WP::get_cbid();
101 if ( ! is_multisite() || get_site_option( 'cookiebot-script-tag-cd-attribute', 'custom' ) === 'custom' ) {
102 $tag_attr = get_option( 'cookiebot-script-tag-cd-attribute', 'async' );
103 } else {
104 $tag_attr = get_site_option( 'cookiebot-script-tag-cd-attribute' );
105 }
106
107 ?>
108 <script type="text/javascript"
109 id="CookieDeclaration"
110 src="<?php echo esc_url( 'https://consent.cookiebot.com/' . $cbid . '/cd.js' ); ?>"
111 <?php if ( ! empty( $lang ) ) : ?>
112 data-culture="<?php echo esc_attr( $lang ); ?>"
113 <?php endif; ?>
114 <?php echo esc_attr( $tag_attr ); ?>
115 />
116 <?php
117 echo '</div>';
118
119 // WordPress core after_widget hook
120 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
121 echo $after_widget;
122 }
123
124 }
125