iubenda Cookie Solution for GDPR - Version 3.2.1

Version Description

  • Bugfix: Show Iubenda legal block in WP Block Editor
Download this release

Release Info

Developer iubenda
Plugin Icon 128x128 iubenda Cookie Solution for GDPR
Version 3.2.1
Comparing to
See all releases

Code changes from version 3.2.0 to 3.2.1

assets/js/legal_block.js ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ( function ( blocks, editor, element, components, _, blockEditor ) {
2
+ var el = element.createElement;
3
+ var RichText = blockEditor.RichText;
4
+ var useBlockProps = blockEditor.useBlockProps;
5
+
6
+ const iconEl = el('svg', {},
7
+ el('path', {
8
+ fill:"#1CC691" ,
9
+ d: "M 11.6671 0 c 3.1311 0 5.6675 2.5268 5.6675 5.6464 c 0 1.3892 -0.5031 2.6608 -1.3408 3.6454 L 17.1974 25.5634 H 6.4376 l 1.1666 -15.9874 A 5.6025 5.6025 90 0 1 6 5.6468 C 6 2.5268 8.5364 0 11.6671 0 z m 1.0762 11.8411 l -1.865 1.8653 v 7.38 h 1.865 V 11.8411 z M 11.6671 4.1886 c -0.7528 0 -1.3628 0.6142 -1.3628 1.3723 c 0 0.7576 0.61 1.372 1.3628 1.372 s 1.3631 -0.6142 1.3631 -1.372 c 0 -0.7582 -0.6104 -1.3723 -1.3631 -1.3723 z"
10
+ } )
11
+ );
12
+
13
+ blocks.registerBlockType( iub_block_js_vars.block_name, {
14
+ title: 'Iubenda',
15
+ icon: iconEl,
16
+ category: 'layout',
17
+ attributes: {
18
+ title: {
19
+ type: 'string',
20
+ default: iub_block_js_vars.iub_legal_block_short_title
21
+ },
22
+ },
23
+ edit: function ( props ) {
24
+ var attributes = props.attributes;
25
+
26
+ return el(
27
+ 'div',
28
+ useBlockProps({ className: props.className }),
29
+ el( RichText, {
30
+ tagName: 'p',
31
+ placeholder: 'Iubenda',
32
+ value: attributes.title,
33
+ onChange: function ( value ) {
34
+ props.setAttributes( { title: value } );
35
+ },
36
+ } ),
37
+ el( 'p', {}, '' ),
38
+ );
39
+ },
40
+ save: function ( props ) {
41
+ var attributes = props.attributes;
42
+
43
+ return el(
44
+ 'div',
45
+ useBlockProps.save( { className: props.className } ),
46
+ el( RichText.Content, {
47
+ tagName: 'p',
48
+ value: attributes.title,
49
+ } ),
50
+ el( 'p', {}, '['+iub_block_js_vars.iub_legal_block_shortcode+']' ),
51
+ );
52
+ },
53
+ } );
54
+ } )(
55
+ window.wp.blocks,
56
+ window.wp.editor,
57
+ window.wp.element,
58
+ window.wp.components,
59
+ window._,
60
+ window.wp.blockEditor
61
+ );
62
+
includes/ProductHelper.php CHANGED
@@ -100,6 +100,41 @@ class ProductHelper
100
  return boolval(trim($iubenda_code));
101
  }
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  /**
104
  * Get intersect supported local languages intersect with iubenda supported languages
105
  *
100
  return boolval(trim($iubenda_code));
101
  }
102
 
103
+ /**
104
+ * Getting public id for current language if stored in database
105
+ * @return array|ArrayAccess|false|mixed
106
+ */
107
+ public function get_public_id_for_current_language(){
108
+ // Checking if there is no public id for current language
109
+ if ( iubenda()->multilang && ! empty( iubenda()->lang_current ) ) {
110
+ $lang_id = iubenda()->lang_current;
111
+ } else {
112
+ $lang_id = 'default';
113
+ }
114
+
115
+ return iub_array_get(iubenda()->options['global_options'], "public_ids.{$lang_id}", false) ?: false;
116
+ }
117
+
118
+ /**
119
+ * Check privacy policy and terms and condition services status and position and codes
120
+ *
121
+ * @return bool
122
+ */
123
+ public function check_pp_tc_status_and_position(){
124
+ $ppStatus = iub_array_get(iubenda()->settings->services, 'pp.status') == 'true';
125
+ $ppPosition = iub_array_get(iubenda()->options['pp'], 'button_position') == 'automatic';
126
+
127
+ $tcStatus = iub_array_get(iubenda()->settings->services, 'tc.status') == 'true';
128
+ $tcPosition = iub_array_get(iubenda()->options['tc'], 'button_position') == 'automatic';
129
+ $quickGeneratorService = new QuickGeneratorService();
130
+
131
+ if (!($ppStatus && $ppPosition && boolval($quickGeneratorService->pp_button())) && !($tcStatus && $tcPosition && boolval($quickGeneratorService->tc_button()))) {
132
+ return false;
133
+ }
134
+
135
+ return true;
136
+ }
137
+
138
  /**
139
  * Get intersect supported local languages intersect with iubenda supported languages
140
  *
includes/QuickGeneratorService.php CHANGED
@@ -283,7 +283,7 @@ class QuickGeneratorService
283
  if($iubenda_section_name == 'iubenda_privacy_policy_solution') {
284
  // Add a widget in the sidebar if the button is positioned automatically
285
  if('automatic' === iub_array_get($section_new_option, 'button_position')){
286
- do_action('iubenda_assign_widget_to_first_sidebar');
287
  }
288
 
289
  // Merge old old PP options with new options to update codes with new style
@@ -298,7 +298,7 @@ class QuickGeneratorService
298
  if($iubenda_section_name == 'iubenda_terms_conditions_solution') {
299
  // Add a widget in the sidebar if the button is positioned automatically
300
  if('automatic' === iub_array_get($section_new_option, 'button_position')){
301
- do_action('iubenda_assign_widget_to_first_sidebar');
302
  }
303
 
304
  // Update TC codes with new button style
@@ -607,7 +607,7 @@ class QuickGeneratorService
607
 
608
  // Add a widget in the sidebar if the button is positioned automatically
609
  if('automatic' === iub_array_get($_POST, 'iubenda_privacy_policy_solution.button_position')){
610
- do_action('iubenda_assign_widget_to_first_sidebar');
611
  }
612
 
613
  // Set the version of PP service as Simplified
283
  if($iubenda_section_name == 'iubenda_privacy_policy_solution') {
284
  // Add a widget in the sidebar if the button is positioned automatically
285
  if('automatic' === iub_array_get($section_new_option, 'button_position')){
286
+ iubenda()->assign_legal_block_or_widget();
287
  }
288
 
289
  // Merge old old PP options with new options to update codes with new style
298
  if($iubenda_section_name == 'iubenda_terms_conditions_solution') {
299
  // Add a widget in the sidebar if the button is positioned automatically
300
  if('automatic' === iub_array_get($section_new_option, 'button_position')){
301
+ iubenda()->assign_legal_block_or_widget();
302
  }
303
 
304
  // Update TC codes with new button style
607
 
608
  // Add a widget in the sidebar if the button is positioned automatically
609
  if('automatic' === iub_array_get($_POST, 'iubenda_privacy_policy_solution.button_position')){
610
+ iubenda()->assign_legal_block_or_widget();
611
  }
612
 
613
  // Set the version of PP service as Simplified
includes/block/IubendaLegalBlock.php ADDED
@@ -0,0 +1,405 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class IubendaLegalBlock
5
+ {
6
+ const IUB_LEGAL_BLOCK_NAME = 'iubenda/legal-block'; // IUB legal block Name
7
+ const IUB_LEGAL_BLOCK_SHORTCODE = 'iub-wp-block-buttons'; // IUB legal block Shortcode
8
+
9
+ /**
10
+ * IubendaLegalBlock constructor.
11
+ */
12
+ public function __construct()
13
+ {
14
+ add_action('iubenda_attach_block_in_footer', [$this, 'attach_legal_block_into_footer']);
15
+
16
+ // Change preregistered default footer content
17
+ add_action('init', [$this, 'change_pre_registered_default_footer_content'], 10, 0);
18
+
19
+ // Attach IUB legal block into WP blocks area
20
+ add_action('admin_init', [$this, 'attach_legal_block_into_block_area'], 10, 0);
21
+
22
+ // Register IUB Legal block shortcode
23
+ add_action('after_setup_theme', [$this, 'register_shortcode']);
24
+ }
25
+
26
+ /**
27
+ * Register IUB Legal block shortcode function.
28
+ *
29
+ * @return void
30
+ */
31
+ public function register_shortcode() {
32
+ add_shortcode(static::IUB_LEGAL_BLOCK_SHORTCODE, [$this, 'render_iub_legal_block']);
33
+ }
34
+
35
+ /**
36
+ * Attach iubenda legal block in footer
37
+ */
38
+ public function attach_legal_block_into_footer()
39
+ {
40
+ // if current theme doesn't supports blocks -> return
41
+ if (!$this->check_current_theme_supports_blocks()) {
42
+ return;
43
+ }
44
+
45
+ // Check if IUB short code exist in footer
46
+ if ($this->check_iub_block_shortcode_exists_in_the_footer()) {
47
+ return;
48
+ }
49
+
50
+ $this->force_append_legal_block_in_footer();
51
+ }
52
+
53
+ /**
54
+ * Detach iubenda legal block from footer
55
+ */
56
+ public function detach_legal_block_from_footer()
57
+ {
58
+ // if current theme doesn't supports blocks -> return
59
+ if (!$this->check_current_theme_supports_blocks()) {
60
+ return;
61
+ }
62
+
63
+ // Check if IUB short code exist in footer
64
+ if ($this->check_iub_block_shortcode_exists_in_the_footer()) {
65
+ $this->force_detach_legal_block_from_footer();
66
+ return;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Attach iubenda legal block in WP blocks area
72
+ */
73
+ public function attach_legal_block_into_block_area()
74
+ {
75
+ // Register IUB js block
76
+ wp_register_script('iubenda-block-editor', IUBENDA_PLUGIN_URL . '/assets/js/legal_block.js', ['wp-blocks', 'wp-block-editor'], iubenda()->version);
77
+ register_block_type(static::IUB_LEGAL_BLOCK_NAME, ['editor_script' => 'iubenda-block-editor',]);
78
+
79
+ // Send iub vars from backend to JS file
80
+ wp_localize_script('iubenda-block-editor', 'iub_block_js_vars', [
81
+ 'block_name' => 'iubenda/legal-block',
82
+ 'iub_legal_block_shortcode' => static::IUB_LEGAL_BLOCK_SHORTCODE,
83
+ 'iub_legal_block_short_title' => __('Legal', 'iubenda'),
84
+ ]);
85
+ }
86
+
87
+ /**
88
+ * Render iubenda legal block and apply filters
89
+ * @return mixed
90
+ */
91
+ public function render_iub_legal_block()
92
+ {
93
+ $html = '';
94
+ $html = apply_filters('before_iub_legal_block_section', $html);
95
+ $html .= '<section>' . $this->iub_legal_block_html($html) . '</section>';
96
+ $html = apply_filters('after_iub_legal_block_section', $html);
97
+
98
+ return $html;
99
+ }
100
+
101
+ /**
102
+ * Check if the current theme support WP blocks or not
103
+ * @return bool
104
+ */
105
+ public function check_current_theme_supports_blocks()
106
+ {
107
+ // Condition if there is no sidebar and the activated theme is working by WP blocks
108
+ global $wp_registered_sidebars;
109
+
110
+ if (!boolval(iub_array_get($wp_registered_sidebars, 'sidebar-1'))) {
111
+ return true;
112
+ }
113
+
114
+ return false;
115
+ }
116
+
117
+ /**
118
+ * Iubenda legal block html
119
+ * @param $html
120
+ * @return mixed|string
121
+ */
122
+ private function iub_legal_block_html($html)
123
+ {
124
+ $quick_generator_service = new QuickGeneratorService();
125
+
126
+ $pp_status = iub_array_get(iubenda()->settings->services, 'pp.status') == 'true';
127
+ $pp_position = iub_array_get(iubenda()->options['pp'], 'button_position') == 'automatic';
128
+ $tc_status = iub_array_get(iubenda()->settings->services, 'tc.status') == 'true';
129
+ $tc_position = iub_array_get(iubenda()->options['tc'], 'button_position') == 'automatic';
130
+
131
+ if ($pp_status && $pp_position) {
132
+ $html .= $quick_generator_service->pp_button();
133
+ }
134
+
135
+ if (($pp_status && $pp_position) && ($tc_status && $tc_position)) {
136
+ $html .= '<br>';
137
+ }
138
+
139
+ if (($tc_status == 'true') && ($tc_position == 'automatic')) {
140
+ $html .= $quick_generator_service->tc_button();
141
+ }
142
+
143
+ return $html;
144
+ }
145
+
146
+ /**
147
+ * Get footer post from database
148
+ * @return mixed|null
149
+ */
150
+ private function get_footer_from_database()
151
+ {
152
+ // Default arguments
153
+ $args = [
154
+ 'post_type' => 'wp_template_part',
155
+ 'post_status' => 'publish',
156
+ 'tax_query' => [
157
+ [
158
+ 'taxonomy' => 'wp_theme',
159
+ 'field' => 'slug',
160
+ 'terms' => [ get_stylesheet() ],
161
+ ],
162
+ ],
163
+ 'posts_per_page' => 1,
164
+ 'no_found_rows' => true,
165
+ ];
166
+
167
+ // Search for footer in database
168
+ $args['name'] = 'footer';
169
+
170
+ // Run WP Query with new args
171
+ $footer_query = new WP_Query($args);
172
+ $footer = $footer_query->have_posts() ? $footer_query->next_post() : null;
173
+
174
+ // Footer exist in database
175
+ if ($footer) {
176
+ return $footer;
177
+ }
178
+
179
+ // Search if it is inserted as a default footer in the database
180
+ $args['name'] = 'default-footer';
181
+
182
+ // Run WP Query with new args
183
+ $footer_query = new WP_Query($args);
184
+ $footer = $footer_query->have_posts() ? $footer_query->next_post() : null;
185
+
186
+ return $footer;
187
+ }
188
+
189
+ /**
190
+ * Check if IUB short code exist in footer
191
+ * @return bool
192
+ */
193
+ private function check_iub_block_shortcode_exists_in_the_footer()
194
+ {
195
+ $footer = $this->get_footer_from_database();
196
+
197
+ if ($footer && $this->check_iub_block_shortcode_exists_in_the_footer_content($footer->post_content)) {
198
+ return true;
199
+ }
200
+
201
+ return false;
202
+ }
203
+
204
+ /**
205
+ * Force append IUB legal block in footer
206
+ */
207
+ private function force_append_legal_block_in_footer()
208
+ {
209
+ $footer = $this->get_footer_from_database();
210
+
211
+ if ($footer) {
212
+ $footer->post_content = $this->insert_iub_block_shortcode_into_footer_by_dom($footer->post_content);
213
+
214
+ $this->update_the_footer_into_database($footer);
215
+ }
216
+
217
+ // There is no footer stored in database then
218
+ // Attach legal block into WP_Block_Patterns as WP default footer and insert this footer into database
219
+ $this->change_pre_registered_default_footer_content(true);
220
+ }
221
+
222
+ /**
223
+ * Insert Legal block into WP content by php DOMDocument
224
+ *
225
+ * @param $footer_content
226
+ * @return false|string
227
+ */
228
+ private function insert_iub_block_shortcode_into_footer_by_dom($footer_content)
229
+ {
230
+ if($this->check_iub_block_shortcode_exists_in_the_footer_content($footer_content)){
231
+ return $footer_content;
232
+ }
233
+
234
+ $dom = new DOMDocument();
235
+ $previous_value = libxml_use_internal_errors(TRUE);
236
+ $dom->loadHTML((string)$footer_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
237
+ libxml_clear_errors();
238
+ libxml_use_internal_errors($previous_value);
239
+
240
+ $target_div = $dom->getElementsByTagName('div')->item(1);
241
+
242
+ if(!$target_div){
243
+ return '';
244
+ }
245
+
246
+ // insert End of Iubenda legal block before start
247
+ $template = $dom->createDocumentFragment();
248
+ $template->appendXML(' <!-- /wp:'. static::IUB_LEGAL_BLOCK_NAME .' --> ');
249
+ $target_div->insertBefore($template, $target_div->firstChild);
250
+
251
+ // Create container div with class 'wp-block-iubenda-legal-block'
252
+ $div = $dom->createElement("div");
253
+ $div->setAttribute("class", "wp-block-iubenda-legal-block");
254
+
255
+ // Append the block title
256
+ $div->appendChild($dom->createElement('p', __('Legal', 'iubenda')));
257
+
258
+ // Append the block content
259
+ $div->appendChild($dom->createElement('p', '[iub-wp-block-buttons]'));
260
+
261
+ // Insert the block into the footer
262
+ $target_div->insertBefore($div, $target_div->firstChild);
263
+
264
+ // Append Start of Iubenda legal block
265
+ $template = $dom->createDocumentFragment();
266
+ $template->appendXML(' <!-- wp:'. static::IUB_LEGAL_BLOCK_NAME .' --> ');
267
+ $target_div->insertBefore($template, $target_div->firstChild);
268
+
269
+ return $dom->saveHTML();
270
+ }
271
+
272
+ /**
273
+ * Remove Legal block from WP content
274
+ *
275
+ * @param $footer_content
276
+ * @return false|string
277
+ */
278
+ private function remove_iub_block_shortcode_from_footer($footer_content)
279
+ {
280
+ $start_of_iub_legal_block = '<!-- wp:'. static::IUB_LEGAL_BLOCK_NAME .' -->';
281
+ $end_of_iub_legal_block = '<!-- /wp:'. static::IUB_LEGAL_BLOCK_NAME .' -->';
282
+
283
+ return $this->iub_delete_in_between($start_of_iub_legal_block, $end_of_iub_legal_block, $footer_content);
284
+ }
285
+
286
+ /**
287
+ * Update the current footer
288
+ *
289
+ * @param $footer
290
+ */
291
+ private function update_the_footer_into_database($footer)
292
+ {
293
+ return wp_update_post($footer);
294
+ }
295
+
296
+ /**
297
+ * Attach legal block into WP_Block_Patterns as WP default footer
298
+ * if $insert_into_database is true insert default footer into database
299
+ *
300
+ * @param bool $insert_into_database
301
+ * @return void
302
+ */
303
+ public function change_pre_registered_default_footer_content($insert_into_database = false)
304
+ {
305
+ $public_id = (new ProductHelper())->get_public_id_for_current_language();
306
+
307
+ // Return false if there is no public id for current language
308
+ if (!($public_id)) {
309
+ return;
310
+ }
311
+
312
+ // Check for PP & TC service status and codes
313
+ if (!(new ProductHelper())->check_pp_tc_status_and_position()) {
314
+ return;
315
+ }
316
+
317
+ $block_registry = WP_Block_Patterns_Registry::get_instance();
318
+
319
+ foreach ( $block_registry->get_all_registered() as $block) {
320
+ $block_name = iub_array_get($block, 'name') ?: null;
321
+
322
+ if (strpos($block_name, 'footer-default') !== false) {
323
+ // Unregister default footer
324
+ $block_registry->unregister(iub_array_get($block, 'name'));
325
+
326
+ // Attach Iubenda legal block in footer content
327
+ $block['content'] = $this->insert_iub_block_shortcode_into_footer_by_dom(iub_array_get($block, 'content'));
328
+
329
+ // Register footer after attached Iubenda legal block on it
330
+ $block_registry->register(iub_array_get($block, 'name'), $block);
331
+
332
+ if ($insert_into_database) {
333
+ // Insert the footer into database
334
+ $this->insert_default_footer_into_database($block);
335
+ }
336
+ }
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Insert default footer into database
342
+ *
343
+ * @param $block
344
+ * @return int|WP_Error
345
+ */
346
+ private function insert_default_footer_into_database($block)
347
+ {
348
+ // taxonomies
349
+ $taxonomies = [
350
+ 'wp_template_part_area' => 'footer',
351
+ 'wp_theme' => get_stylesheet(), // Current active theme slug
352
+ ];
353
+
354
+ // New footer data
355
+ $footer = [
356
+ 'post_title' => 'Footer',
357
+ 'post_content' => $block['content'],
358
+ 'post_status' => 'publish',
359
+ 'post_author' => 1,
360
+ 'post_type' => 'wp_template_part',
361
+ 'post_category' => [ 'footer' ],
362
+ 'tax_input' => $taxonomies
363
+ ];
364
+
365
+ // Insert the new footer into the database
366
+ wp_insert_post($footer);
367
+ }
368
+
369
+ /**
370
+ * Force detach IUB legal block from footer
371
+ */
372
+ private function force_detach_legal_block_from_footer()
373
+ {
374
+ $footer = $this->get_footer_from_database();
375
+
376
+ if ($footer) {
377
+ $footer->post_content = $this->remove_iub_block_shortcode_from_footer($footer->post_content);
378
+
379
+ $this->update_the_footer_into_database($footer);
380
+ }
381
+ }
382
+
383
+ private function iub_delete_in_between($beginning, $end, $string) {
384
+ $beginning_pos = strpos($string, $beginning);
385
+ $end_pos = strpos($string, $end);
386
+ if ($beginning_pos === false || $end_pos === false) {
387
+ return $string;
388
+ }
389
+
390
+ $text_to_delete = substr($string, $beginning_pos, ($end_pos + strlen($end)) - $beginning_pos);
391
+
392
+ return $this->iub_delete_in_between($beginning, $end, str_replace($text_to_delete, '', $string)); // recursion to ensure occurrences are removed
393
+ }
394
+
395
+ /**
396
+ * Check IUB block shortcode exists in the footer content
397
+ * @param $footer_content
398
+ * @return bool
399
+ */
400
+ private function check_iub_block_shortcode_exists_in_the_footer_content($footer_content)
401
+ {
402
+ return strpos($footer_content, '[iub-wp-block-buttons]') !== false;
403
+ }
404
+
405
+ }
includes/settings.php CHANGED
@@ -1308,7 +1308,7 @@ class iubenda_Settings {
1308
  $product_option['button_position'] = 'automatic';
1309
 
1310
  // Add a widget in the sidebar
1311
- do_action('iubenda_assign_widget_to_first_sidebar');
1312
  }
1313
 
1314
  $product_option["code_{$lang_id}"] = stripslashes($code);
@@ -1319,7 +1319,7 @@ class iubenda_Settings {
1319
 
1320
  if (in_array($product_key, ['pp', 'tc'])) {
1321
  // Add a widget in the sidebar if the button is positioned automatically
1322
- do_action('iubenda_assign_widget_to_first_sidebar');
1323
  }
1324
 
1325
  //add version if Iubenda privacy policy solution activated
@@ -1399,7 +1399,7 @@ class iubenda_Settings {
1399
  $product_option['button_position'] = 'automatic';
1400
 
1401
  // Add a widget in the sidebar
1402
- do_action('iubenda_assign_widget_to_first_sidebar');
1403
  }
1404
 
1405
  $product_option["code_{$lang_id}"] = stripslashes($code);
@@ -1410,7 +1410,7 @@ class iubenda_Settings {
1410
 
1411
  if (in_array($product_key, ['pp', 'tc'])) {
1412
  // Add a widget in the sidebar if the button is positioned automatically
1413
- do_action('iubenda_assign_widget_to_first_sidebar');
1414
  }
1415
 
1416
  //add version if Iubenda privacy policy solution activated
1308
  $product_option['button_position'] = 'automatic';
1309
 
1310
  // Add a widget in the sidebar
1311
+ iubenda()->assign_legal_block_or_widget();
1312
  }
1313
 
1314
  $product_option["code_{$lang_id}"] = stripslashes($code);
1319
 
1320
  if (in_array($product_key, ['pp', 'tc'])) {
1321
  // Add a widget in the sidebar if the button is positioned automatically
1322
+ iubenda()->assign_legal_block_or_widget();
1323
  }
1324
 
1325
  //add version if Iubenda privacy policy solution activated
1399
  $product_option['button_position'] = 'automatic';
1400
 
1401
  // Add a widget in the sidebar
1402
+ iubenda()->assign_legal_block_or_widget();
1403
  }
1404
 
1405
  $product_option["code_{$lang_id}"] = stripslashes($code);
1410
 
1411
  if (in_array($product_key, ['pp', 'tc'])) {
1412
  // Add a widget in the sidebar if the button is positioned automatically
1413
+ iubenda()->assign_legal_block_or_widget();
1414
  }
1415
 
1416
  //add version if Iubenda privacy policy solution activated
includes/widget/IubendaLegalWidget.php CHANGED
@@ -218,6 +218,21 @@ class IubendaLegalWidget extends WP_Widget
218
  public function register_widget() {
219
  register_widget(__CLASS__);
220
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  }
222
 
223
 
218
  public function register_widget() {
219
  register_widget(__CLASS__);
220
  }
221
+
222
+ /**
223
+ * Check current theme supports widget
224
+ */
225
+ public function check_current_theme_supports_widget()
226
+ {
227
+ global $wp_registered_sidebars;
228
+
229
+ // If sidebar-1 registered and activated
230
+ if (iub_array_get($wp_registered_sidebars, 'sidebar-1')) {
231
+ return true;
232
+ }
233
+
234
+ return false;
235
+ }
236
  }
237
 
238
 
iubenda_cookie_solution.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Cookie and Consent Solution for the GDPR & ePrivacy
4
  Plugin URI: https://www.iubenda.com
5
  Description: An All-in-One approach developed by iubenda, which includes functionalities of two powerful solutions that help to make your website GDPR and ePrivacy compliant.
6
- Version: 3.2.0
7
  Author: iubenda
8
  Author URI: https://www.iubenda.com
9
  License: MIT License
@@ -32,9 +32,11 @@ define( 'IUB_DEBUG', false );
32
  * iubenda final class.
33
  *
34
  * @property-read iubenda_Settings $settings
 
 
35
  *
36
  * @class iubenda
37
- * @version 3.2.0
38
  */
39
  class iubenda {
40
 
@@ -92,7 +94,7 @@ class iubenda {
92
  )
93
  );
94
  public $base_url;
95
- public $version = '3.2.0';
96
  public $activation = array(
97
  'update_version' => 0,
98
  'update_notice' => true,
@@ -166,6 +168,7 @@ class iubenda {
166
  self::$instance->forms = new iubenda_Forms();
167
  self::$instance->settings = new iubenda_Settings();
168
  self::$instance->widget = new IubendaLegalWidget();
 
169
  }
170
 
171
  return self::$instance;
@@ -236,7 +239,6 @@ class iubenda {
236
  return $actions;
237
  }
238
 
239
-
240
  /**
241
  * Setup plugin constants.
242
  *
@@ -263,6 +265,7 @@ class iubenda {
263
  include_once( IUBENDA_PLUGIN_PATH . 'includes/PrivacyPolicyGenerator.php' );
264
  include_once( IUBENDA_PLUGIN_PATH . 'includes/ServiceRating.php' );
265
  include_once( IUBENDA_PLUGIN_PATH . 'includes/widget/IubendaLegalWidget.php' );
 
266
  include_once( IUBENDA_PLUGIN_PATH . 'includes/ProductHelper.php' );
267
  include_once( IUBENDA_PLUGIN_PATH . 'includes/LanguageHelper.php' );
268
  }
@@ -367,6 +370,9 @@ class iubenda {
367
  delete_option( 'iubenda_tc_page_configuration' );
368
  delete_option( 'iubenda_terms_conditions_solution' );
369
  delete_option( iubenda_Settings::IUB_NOTIFICATIONS );
 
 
 
370
  }
371
 
372
  // remove radar options from database
@@ -1205,6 +1211,34 @@ class iubenda {
1205
  return version_compare( $db_version, $this->version, '<' );
1206
  }
1207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1208
  }
1209
 
1210
  if (!function_exists('iub_array_get')) {
3
  Plugin Name: Cookie and Consent Solution for the GDPR & ePrivacy
4
  Plugin URI: https://www.iubenda.com
5
  Description: An All-in-One approach developed by iubenda, which includes functionalities of two powerful solutions that help to make your website GDPR and ePrivacy compliant.
6
+ Version: 3.2.1
7
  Author: iubenda
8
  Author URI: https://www.iubenda.com
9
  License: MIT License
32
  * iubenda final class.
33
  *
34
  * @property-read iubenda_Settings $settings
35
+ * @property IubendaLegalWidget $widget
36
+ * @property IubendaLegalBlock $block
37
  *
38
  * @class iubenda
39
+ * @version 3.2.1
40
  */
41
  class iubenda {
42
 
94
  )
95
  );
96
  public $base_url;
97
+ public $version = '3.2.1';
98
  public $activation = array(
99
  'update_version' => 0,
100
  'update_notice' => true,
168
  self::$instance->forms = new iubenda_Forms();
169
  self::$instance->settings = new iubenda_Settings();
170
  self::$instance->widget = new IubendaLegalWidget();
171
+ self::$instance->block = new IubendaLegalBlock();
172
  }
173
 
174
  return self::$instance;
239
  return $actions;
240
  }
241
 
 
242
  /**
243
  * Setup plugin constants.
244
  *
265
  include_once( IUBENDA_PLUGIN_PATH . 'includes/PrivacyPolicyGenerator.php' );
266
  include_once( IUBENDA_PLUGIN_PATH . 'includes/ServiceRating.php' );
267
  include_once( IUBENDA_PLUGIN_PATH . 'includes/widget/IubendaLegalWidget.php' );
268
+ include_once( IUBENDA_PLUGIN_PATH . 'includes/block/IubendaLegalBlock.php' );
269
  include_once( IUBENDA_PLUGIN_PATH . 'includes/ProductHelper.php' );
270
  include_once( IUBENDA_PLUGIN_PATH . 'includes/LanguageHelper.php' );
271
  }
370
  delete_option( 'iubenda_tc_page_configuration' );
371
  delete_option( 'iubenda_terms_conditions_solution' );
372
  delete_option( iubenda_Settings::IUB_NOTIFICATIONS );
373
+
374
+ // Detach iubenda legal block from footer
375
+ $this->block->detach_legal_block_from_footer();
376
  }
377
 
378
  // remove radar options from database
1211
  return version_compare( $db_version, $this->version, '<' );
1212
  }
1213
 
1214
+ /**
1215
+ * Decide which will be included into footer (Block or Widget)
1216
+ */
1217
+ public function assign_legal_block_or_widget()
1218
+ {
1219
+ // If current theme supports widget
1220
+ if ($this->widget->check_current_theme_supports_widget()) {
1221
+ do_action('iubenda_assign_widget_to_first_sidebar');
1222
+ }
1223
+
1224
+ // if current theme supports blocks
1225
+ if ($this->block->check_current_theme_supports_blocks()) {
1226
+ do_action('iubenda_attach_block_in_footer');
1227
+ }
1228
+ }
1229
+
1230
+ /**
1231
+ * Check if we support current theme to attach legal
1232
+ */
1233
+ public function check_if_we_support_current_theme_to_attach_legal()
1234
+ {
1235
+ if ($this->widget->check_current_theme_supports_widget() || $this->block->check_current_theme_supports_blocks()) {
1236
+ return true;
1237
+ }
1238
+
1239
+ return false;
1240
+ }
1241
+
1242
  }
1243
 
1244
  if (!function_exists('iub_array_get')) {
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: cookie banner, cookie law, eprivacy, gdpr, ukgdpr, ccpa, caloppa, lgpd, ds
5
  Requires at least: 5.0
6
  Requires PHP: 7.0.0
7
  Tested up to: 6.0
8
- Stable tag: 3.2.0
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
@@ -254,6 +254,9 @@ The Brazilian General Data Protection Law, the ***Lei Geral de Proteção de Dad
254
 
255
  == Changelog ==
256
 
 
 
 
257
  = 3.2.0 =
258
  * Set EN as default language on QuickGenerator
259
  * Bugfix: PCP detection not correctly rated
@@ -710,8 +713,5 @@ The Brazilian General Data Protection Law, the ***Lei Geral de Proteção de Dad
710
 
711
  == Upgrade Notice ==
712
 
713
- = 3.2.0 =
714
- * Set EN as default language on QuickGenerator
715
- * Bugfix: PCP detection not correctly rated
716
- * Translate plugin into [IT, FR, PT-BR, ES, NL]
717
- * Pre-select website language on the language setup dropdown
5
  Requires at least: 5.0
6
  Requires PHP: 7.0.0
7
  Tested up to: 6.0
8
+ Stable tag: 3.2.1
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
254
 
255
  == Changelog ==
256
 
257
+ = 3.2.1 =
258
+ * Bugfix: Show Iubenda legal block in WP Block Editor
259
+
260
  = 3.2.0 =
261
  * Set EN as default language on QuickGenerator
262
  * Bugfix: PCP detection not correctly rated
713
 
714
  == Upgrade Notice ==
715
 
716
+ = 3.2.1 =
717
+ * Bugfix: Show Iubenda legal block in WP Block Editor
 
 
 
views/partials/buttonPosition.php CHANGED
@@ -11,15 +11,21 @@
11
  </label>
12
  </div>
13
  <?php
14
- global $wp_registered_sidebars;
 
 
 
 
 
 
 
 
15
 
16
- // If sidebar-1 not registered or not activated
17
- if (!boolval(iub_array_get($wp_registered_sidebars, 'sidebar-1'))) {
18
  ?>
19
  <section id="pp_button_position_automatically" class="pp_button_position <?php echo iub_array_get(iubenda()->options['pp'], 'button_position') == 'automatic' ?:'hidden' ; ?>">
20
  <div class="notice notice--warning mt-2 mb-4 p-3 d-flex align-items-center text-warning text-xs">
21
  <img class="mr-2" src="<?php echo IUBENDA_PLUGIN_URL ?>/assets/images/warning-icon.svg">
22
- <p><?php echo sprintf( __( 'We were not able to add a "Legal" widget to the footer as your theme is not compatible, you can position the "Legal" widget manually from <a href="%s" target="_blank">here</a>.', 'iubenda' ), esc_url( admin_url( 'widgets.php' ) ) ) ?></p>
23
  </div>
24
  </section>
25
  <?php
11
  </label>
12
  </div>
13
  <?php
14
+ // Check if we support current theme to attach legal
15
+ if (!iubenda()->check_if_we_support_current_theme_to_attach_legal()) {
16
+ $url = 'javascript:void(0)';
17
+
18
+ if(iubenda()->widget->check_current_theme_supports_widget()){
19
+ $url = admin_url( 'widgets.php' );
20
+ }elseif(iubenda()->block->check_current_theme_supports_blocks()){
21
+ $url = admin_url( 'site-editor.php' );
22
+ }
23
 
 
 
24
  ?>
25
  <section id="pp_button_position_automatically" class="pp_button_position <?php echo iub_array_get(iubenda()->options['pp'], 'button_position') == 'automatic' ?:'hidden' ; ?>">
26
  <div class="notice notice--warning mt-2 mb-4 p-3 d-flex align-items-center text-warning text-xs">
27
  <img class="mr-2" src="<?php echo IUBENDA_PLUGIN_URL ?>/assets/images/warning-icon.svg">
28
+ <p><?php echo sprintf( __( 'We were not able to add a "Legal" widget/block to the footer as your theme is not compatible, you can position the "Legal" widget/block manually from <a href="%s" target="_blank">here</a>.', 'iubenda' ), esc_url( $url ) ) ?></p>
29
  </div>
30
  </section>
31
  <?php
views/partials/modals/modal_almost_there.php CHANGED
@@ -46,14 +46,20 @@
46
  <section id="section-<?php echo $key; ?>" class="<?php echo $service['status']=='true' ? '':'hidden'; ?>">
47
  <h4 class="mb-3"><?php echo $service['label']; ?></h4>
48
  <?php
49
- global $wp_registered_sidebars;
 
 
 
 
 
 
 
 
50
 
51
- // If sidebar-1 not registered or not activated
52
- if (in_array($key, ['pp', 'tc']) && !boolval(iub_array_get($wp_registered_sidebars, 'sidebar-1'))) {
53
  ?>
54
  <div class="notice notice--warning mt-2 mb-4 p-3 d-flex align-items-center text-warning text-xs">
55
  <img class="mr-2" style="width: 3rem !important" src="<?php echo IUBENDA_PLUGIN_URL ?>/assets/images/warning-icon.svg">
56
- <p><?php echo sprintf( __( 'We were not able to add a "Legal" widget to the footer as your theme is not compatible, you can position the "Legal" widget manually from <a href="%s" target="_blank">here</a>.', 'iubenda' ), esc_url( admin_url( 'widgets.php' ) ) ) ?></p>
57
  </div>
58
  <?php
59
  }
46
  <section id="section-<?php echo $key; ?>" class="<?php echo $service['status']=='true' ? '':'hidden'; ?>">
47
  <h4 class="mb-3"><?php echo $service['label']; ?></h4>
48
  <?php
49
+ // Check if we support current theme to attach legal
50
+ if (!iubenda()->check_if_we_support_current_theme_to_attach_legal()) {
51
+ $url = 'javascript:void(0)';
52
+
53
+ if(iubenda()->widget->check_current_theme_supports_widget()){
54
+ $url = admin_url( 'widgets.php' );
55
+ }elseif(iubenda()->block->check_current_theme_supports_blocks()){
56
+ $url = admin_url( 'site-editor.php' );
57
+ }
58
 
 
 
59
  ?>
60
  <div class="notice notice--warning mt-2 mb-4 p-3 d-flex align-items-center text-warning text-xs">
61
  <img class="mr-2" style="width: 3rem !important" src="<?php echo IUBENDA_PLUGIN_URL ?>/assets/images/warning-icon.svg">
62
+ <p><?php echo sprintf( __( 'We were not able to add a "Legal" widget/block to the footer as your theme is not compatible, you can position the "Legal" widget/block manually from <a href="%s" target="_blank">here</a>.', 'iubenda' ), esc_url( $url ) ) ?></p>
63
  </div>
64
  <?php
65
  }
views/tc-configuration.php CHANGED
@@ -66,15 +66,21 @@
66
  </label>
67
  </div>
68
  <?php
69
- global $wp_registered_sidebars;
 
 
 
 
 
 
 
 
70
 
71
- // If sidebar-1 not registered or not activated
72
- if (!boolval(iub_array_get($wp_registered_sidebars, 'sidebar-1'))){
73
  ?>
74
  <section id="tc_button_position_automatic" class="tc_button_position <?php echo iub_array_get(iubenda()->options['tc'], 'button_position') == 'automatic' ?:'hidden' ; ?>">
75
  <div class="notice notice--warning mt-2 mb-4 p-3 d-flex align-items-center text-warning text-xs">
76
  <img class="mr-2" src="<?php echo IUBENDA_PLUGIN_URL ?>/assets/images/warning-icon.svg">
77
- <p><?php echo sprintf( __( 'We were not able to add a "Legal" widget to the footer as your theme is not compatible, you can position the "Legal" widget manually from <a href="%s" target="_blank">here</a>.', 'iubenda' ), esc_url( admin_url( 'widgets.php' ) ) ) ?></p>
78
  </div>
79
  </section>
80
  <?php
66
  </label>
67
  </div>
68
  <?php
69
+ // Check if we support current theme to attach legal
70
+ if (!iubenda()->check_if_we_support_current_theme_to_attach_legal()) {
71
+ $url = 'javascript:void(0)';
72
+
73
+ if(iubenda()->widget->check_current_theme_supports_widget()){
74
+ $url = admin_url( 'widgets.php' );
75
+ }elseif(iubenda()->block->check_current_theme_supports_blocks()){
76
+ $url = admin_url( 'site-editor.php' );
77
+ }
78
 
 
 
79
  ?>
80
  <section id="tc_button_position_automatic" class="tc_button_position <?php echo iub_array_get(iubenda()->options['tc'], 'button_position') == 'automatic' ?:'hidden' ; ?>">
81
  <div class="notice notice--warning mt-2 mb-4 p-3 d-flex align-items-center text-warning text-xs">
82
  <img class="mr-2" src="<?php echo IUBENDA_PLUGIN_URL ?>/assets/images/warning-icon.svg">
83
+ <p><?php echo sprintf( __( 'We were not able to add a "Legal" widget/block to the footer as your theme is not compatible, you can position the "Legal" widget/block manually from <a href="%s" target="_blank">here</a>.', 'iubenda' ), esc_url( $url ) ) ?></p>
84
  </div>
85
  </section>
86
  <?php