PluginProbe ʕ •ᴥ•ʔ
Complianz – GDPR/CCPA Cookie Consent / 6.5.6
Complianz – GDPR/CCPA Cookie Consent v6.5.6
7.4.6 trunk 6.5.6 7.0.4 7.0.5 7.1.0 7.1.4 7.1.5 7.2.0 7.3.0 7.3.1 7.4.0 7.4.0.1 7.4.1 7.4.2 7.4.3 7.4.4 7.4.4.1 7.4.4.2 7.4.5 beta
complianz-gdpr / upgrade.php
complianz-gdpr Last commit date
DNSMPD 2 years ago assets 2 years ago config 2 years ago cookie 2 years ago cookiebanner 2 years ago cron 3 years ago grid 3 years ago gutenberg 2 years ago integrations 2 years ago languages 2 years ago proof-of-consent 3 years ago rest-api 3 years ago settings 2 years ago shepherd 3 years ago templates 2 years ago upgrade 2 years ago LICENSE.txt 4 years ago README.md 4 years ago callback-notices.php 3 years ago class-admin.php 2 years ago class-company.php 4 years ago class-cookie-blocker.php 2 years ago class-document.php 2 years ago class-export.php 3 years ago class-field.php 2 years ago class-installer.php 2 years ago class-review.php 3 years ago class-wizard.php 3 years ago complianz-gpdr.php 2 years ago composer.json 3 years ago functions.php 2 years ago gulpfile.js 3 years ago index.php 7 years ago loco.xml 4 years ago readme.txt 2 years ago security.md 2 years ago system-status.php 3 years ago uninstall.php 3 years ago upgrade.php 2 years ago
upgrade.php
1015 lines
1 <?php
2 defined( 'ABSPATH' ) or die();
3 add_action( 'init', 'cmplz_check_upgrade', 10, 2 );
4
5 /**
6 * Run an upgrade procedure if the version has changed
7 */
8 function cmplz_check_upgrade() {
9 #only run upgrade check if cron, or if admin.
10 if ( !is_admin() && !wp_doing_cron() ) {
11 return;
12 }
13 $prev_version = get_option( 'cmplz-current-version', false );
14 if ( $prev_version === cmplz_version ) {
15 return;
16 }
17
18 /**
19 * Set a "first version" variable, so we can check if some notices need to be shown
20 */
21 if ( ! $prev_version ) {
22 update_option( 'cmplz_first_version', cmplz_version, false );
23 }
24
25 /*
26 * change googlemaps into google-maps
27 * */
28 if ( $prev_version
29 && version_compare( $prev_version, '4.0.0', '<' )
30 ) {
31 $wizard_settings = get_option( 'complianz_options_wizard' );
32 if ( isset( $wizard_settings['thirdparty_services_on_site']['googlemaps'] )
33 && $wizard_settings['thirdparty_services_on_site']['googlemaps']
34 == 1
35 ) {
36 unset( $wizard_settings['thirdparty_services_on_site']['googlemaps'] );
37 $wizard_settings['thirdparty_services_on_site']['google-maps'] = 1;
38 update_option( 'complianz_options_wizard', $wizard_settings );
39 }
40 }
41
42 /**
43 * upgrade existing eu and uk settings to separate uk optinstats
44 */
45
46 if ( $prev_version
47 && version_compare( $prev_version, '4.0.0', '<' )
48 ) {
49 if ( cmplz_has_region( 'eu' ) && cmplz_has_region( 'uk' ) ) {
50 $banners = cmplz_get_cookiebanners();
51 foreach ( $banners as $banner ) {
52 $banner = new CMPLZ_COOKIEBANNER( $banner->ID );
53 $banner->use_categories_optinstats
54 = $banner->use_categories;
55 $banner->save();
56 }
57 }
58
59 }
60
61 /**
62 * migrate to anonymous if anonymous settings are selected
63 */
64
65 if ( $prev_version
66 && version_compare( $prev_version, '4.0.4', '<' )
67 ) {
68 $selected_stat_service = cmplz_get_value( 'compile_statistics' );
69 if ( $selected_stat_service === 'google-analytics'
70 || $selected_stat_service === 'matomo'
71 || $selected_stat_service === 'google-tag-manager'
72 ) {
73 $service_name
74 = COMPLIANZ::$cookie_admin->convert_slug_to_name( $selected_stat_service );
75
76 //check if we have ohter types of this service, to prevent double services here.
77 $service_anonymized = new CMPLZ_SERVICE( $service_name . ' (anonymized)' );
78 $service = new CMPLZ_SERVICE( $service_name );
79
80 //check if we have two service types. If so, just delete the anonymized one
81 if ( $service_anonymized->ID && $service->ID ) {
82 $service_anonymized->delete();
83 } else if ( $service_anonymized->ID && ! $service->ID ) {
84 //just one. If it's the anonymous service, rename, and save it.
85 $service_anonymized->name = $service_name;
86 $service_anonymized->save();
87 }
88 }
89 }
90
91 /**
92 * ask consent for cookiedatabase sync and reference, and start sync and scan
93 */
94
95 if ( $prev_version
96 && version_compare( $prev_version, '4.0.4', '<' )
97 ) {
98
99 //upgrade option to transient
100 if ( ! get_transient( 'cmplz_processed_pages_list' ) ) {
101 set_transient( 'cmplz_processed_pages_list',
102 get_option( 'cmplz_processed_pages_list' ),
103 MONTH_IN_SECONDS );
104 }
105
106 //reset scan, delayed
107 COMPLIANZ::$cookie_admin->reset_pages_list( true );
108 //initialize a sync
109 update_option( 'cmplz_run_cdb_sync_once', true, false );
110 }
111
112 /**
113 * upgrade publish date to more generic unix
114 */
115
116 if ( $prev_version
117 && version_compare( $prev_version, '4.2', '<' )
118 ) {
119 $publish_date = strtotime( get_option( 'cmplz_publish_date' ) );
120 if ( intval( $publish_date ) > 0 ) {
121 update_option( 'cmplz_publish_date',
122 intval( $publish_date ) );
123 }
124 }
125
126 /**
127 * upgrade to new custom and generated document settings
128 */
129 if ( $prev_version
130 && version_compare( $prev_version, '4.4.0', '<' )
131 ) {
132 //upgrade cookie policy setting to new field
133 $wizard_settings = get_option( 'complianz_options_wizard' );
134 if ( isset( $wizard_settings["cookie-policy-type"] ) ) {
135 $value = $wizard_settings["cookie-policy-type"];
136 unset( $wizard_settings["cookie-policy-type"] );
137 //upgrade cookie policy custom url
138 if ( $value === 'custom' ) {
139 $url = cmplz_get_value( 'custom-cookie-policy-url' );
140 update_option( "cmplz_cookie-statement_custom_page", $url );
141 unset( $wizard_settings["custom-cookie-policy-url"] );
142 } else {
143 $value = 'generated';
144 }
145 } else {
146 $value = 'generated';
147 }
148
149 $wizard_settings['cookie-statement'] = $value;
150 $wizard_settings['impressum'] = 'none';
151
152 //upgrade privacy statement settings
153 $value = $wizard_settings["privacy-statement"];
154
155 if ( $value === 'yes' ) {
156 $value = 'generated';
157 } else {
158 $wp_privacy_policy = get_option( 'wp_page_for_privacy_policy' );
159 if ( $wp_privacy_policy ) {
160 $value = 'custom';
161 update_option( "cmplz_privacy-statement_custom_page", $wp_privacy_policy );
162 } else {
163 $value = 'none';
164 }
165 }
166 $wizard_settings['privacy-statement'] = $value;
167
168 //upgrade disclaimer settings
169 $value = $wizard_settings["disclaimer"];
170 if ( $value === 'yes' ) {
171 $value = 'generated';
172 } else {
173 $value = 'none';
174 }
175 $wizard_settings['disclaimer'] = $value;
176
177 //save the data
178 update_option( 'complianz_options_wizard', $wizard_settings );
179 }
180
181 /**
182 * upgrade to new category field
183 */
184 if ( $prev_version
185 && version_compare( $prev_version, '4.6.0', '<' )
186 ) {
187
188 $banners = cmplz_get_cookiebanners();
189 if ( $banners ) {
190 foreach ( $banners as $banner_item ) {
191 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID, false );
192 $banner->banner_version ++;
193 if ( $banner->use_categories ) {
194 $banner->use_categories = 'legacy';
195 } else {
196 $banner->use_categories = 'no';
197 }
198 if ( $banner->use_categories_optinstats ) {
199 $banner->use_categories_optinstats = 'legacy';
200 } else {
201 $banner->use_categories_optinstats = 'no';
202 }
203 //also set the deny button to banner color, to make sure users start with correct colors
204 $banner->functional_background_color = $banner->colorpalette_background['color'];
205 $banner->functional_border_color = $banner->colorpalette_background['border'];
206 $banner->functional_text_color = $banner->colorpalette_text['color'];
207 $banner->save();
208 }
209 }
210 }
211
212 /**
213 * migrate policy id to network option for multisites
214 */
215
216 if ( $prev_version && version_compare( $prev_version, '4.6.7', '<' )
217 ) {
218 if ( is_multisite() ) {
219 update_site_option( 'complianz_active_policy_id', get_option( 'complianz_active_policy_id', 1 ) );
220 }
221 }
222
223 /**
224 * migrate odd numbers
225 */
226 if ( $prev_version && version_compare( $prev_version, '4.6.8', '<' )
227 ) {
228 $banners = cmplz_get_cookiebanners();
229 if ( $banners ) {
230 foreach ( $banners as $banner_item ) {
231 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
232 if ( $banner->banner_width % 2 == 1 ) {
233 $banner->banner_width ++;
234 }
235 $banner->save();
236 }
237 }
238 }
239
240 if ( $prev_version
241 && version_compare( $prev_version, '4.7.1', '<' )
242 ) {
243 //upgrade cookie policy setting to new field
244 $wizard_settings = get_option( 'complianz_options_wizard' );
245 $wizard_settings['block_recaptcha_service'] = 'yes';
246 update_option( 'complianz_options_wizard', $wizard_settings );
247 }
248
249 if ( $prev_version
250 && version_compare( $prev_version, '4.9.6', '<' )
251 ) {
252 //this branch aims to revoke consent and clear all cookies. We increase the policy id to do this.
253 COMPLIANZ::$cookie_admin->upgrade_active_policy_id();
254 }
255
256 if ( $prev_version
257 && version_compare( $prev_version, '4.9.7', '<' )
258 ) {
259 update_option( 'cmplz_show_terms_conditions_notice', time(), false );
260 }
261
262 /**
263 * upgrade to new cookie banner, and 5.0 message option
264 */
265
266 if ( $prev_version && version_compare( $prev_version, '5.0.0', '<' ) ) {
267 update_option( 'cmplz_upgraded_to_five', true, false );
268
269 //clear notices cache, as the array structure has changed
270 delete_transient( 'complianz_warnings' );
271 global $wpdb;
272
273 $banners = cmplz_get_cookiebanners();
274 if ( $banners ) {
275 foreach ( $banners as $banner_item ) {
276 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID, false );
277 $sql = "select * from {$wpdb->prefix}cmplz_cookiebanners where ID = {$banner_item->ID}";
278 $result = $wpdb->get_row( $sql );
279
280 if ( $result ) {
281 //reset to arrays
282 if (!is_array($banner->colorpalette_background)) {
283 $banner->colorpalette_background = array();
284 }
285 if (!is_array($banner->colorpalette_text)) {
286 $banner->colorpalette_text = array();
287 }
288 if (!is_array($banner->colorpalette_toggles)) {
289 $banner->colorpalette_toggles = array();
290 }
291 if (!is_array($banner->colorpalette_button_accept)) {
292 $banner->colorpalette_button_accept = array();
293 }
294 if (!is_array($banner->colorpalette_button_deny)) {
295 $banner->colorpalette_button_deny = array();
296 }
297 if (!is_array($banner->colorpalette_button_settings)) {
298 $banner->colorpalette_button_settings = array();
299 }
300 $banner->colorpalette_background['color'] = empty( $result->popup_background_color ) ? '#f1f1f1' : $result->popup_background_color;
301 $banner->colorpalette_background['border'] = empty( $result->popup_background_color ) ? '#f1f1f1' : $result->popup_background_color;
302 $banner->colorpalette_text['color'] = empty( $result->popup_text_color ) ? '#191e23' : $result->popup_text_color;
303 $banner->colorpalette_text['hyperlink'] = empty( $result->popup_text_color ) ? '#191e23' : $result->popup_text_color;
304 $banner->colorpalette_toggles['background'] = empty( $result->slider_background_color ) ? '#21759b' : $result->slider_background_color;
305 $banner->colorpalette_toggles['bullet'] = empty( $result->slider_bullet_color ) ? '#ffffff' : $result->slider_bullet_color;
306 $banner->colorpalette_toggles['inactive'] = empty( $result->slider_background_color_inactive ) ? '#F56E28' : $result->slider_background_color_inactive;
307
308 $consenttypes = cmplz_get_used_consenttypes();
309 $optout_only = false;
310 if ( in_array( 'optout', $consenttypes ) && count( $consenttypes ) === 1 ) {
311 $optout_only = true;
312 }
313
314 if ( $banner->use_categories === 'no' || $optout_only ) {
315 $banner->colorpalette_button_accept['background'] = empty( $result->button_background_color ) ? '#21759b' : $result->button_background_color;
316 $banner->colorpalette_button_accept['border'] = empty( $result->border_color ) ? '#21759b' : $result->border_color;
317 $banner->colorpalette_button_accept['text'] = empty( $result->button_text_color ) ? '#ffffff' : $result->button_text_color;
318 } else {
319 $banner->colorpalette_button_accept['background'] = empty( $result->accept_all_background_color ) ? '#21759b' : $result->accept_all_background_color;
320 $banner->colorpalette_button_accept['border'] = empty( $result->accept_all_border_color ) ? '#21759b' : $result->accept_all_border_color;
321 $banner->colorpalette_button_accept['text'] = empty( $result->accept_all_text_color ) ? '#ffffff' : $result->accept_all_text_color;
322 }
323 $banner->colorpalette_button_deny['background'] = empty( $result->functional_background_color ) ? '#f1f1f1' : $result->functional_background_color;
324 $banner->colorpalette_button_deny['border'] = empty( $result->functional_border_color ) ? '#f1f1f1' : $result->functional_border_color;
325 $banner->colorpalette_button_deny['text'] = empty( $result->functional_text_color ) ? '#21759b' : $result->functional_text_color;
326
327 $banner->colorpalette_button_settings['background'] = empty( $result->button_background_color ) ? '#f1f1f1' : $result->button_background_color;
328 $banner->colorpalette_button_settings['border'] = empty( $result->border_color ) ? '#21759b' : $result->border_color;
329 $banner->colorpalette_button_settings['text'] = empty( $result->button_text_color ) ? '#21759b' : $result->button_text_color;
330 if ( $banner->theme === 'edgeless' ) {
331 $banner->buttons_border_radius = array(
332 'top' => '0',
333 'right' => '0',
334 'bottom' => '0',
335 'left' => '0',
336 'type' => 'px',
337 );
338 }
339
340 $banner->save();
341 }
342
343 }
344 }
345 /**
346 * Move custom scripts from 'wizard' to 'custom-scripts'
347 */
348 //upgrade cookie policy setting to new field
349 $wizard_settings = get_option( 'complianz_options_wizard' );
350 $custom_scripts = array();
351 if ( isset( $wizard_settings['statistics_script'] ) ) {
352 $custom_scripts['statistics_script'] = $wizard_settings['statistics_script'];
353 }
354 if ( isset( $wizard_settings['cookie_scripts'] ) ) {
355 $custom_scripts['cookie_scripts'] = $wizard_settings['cookie_scripts'];
356 }
357 if ( isset( $wizard_settings['cookie_scripts_async'] ) ) {
358 $custom_scripts['cookie_scripts_async'] = $wizard_settings['cookie_scripts_async'];
359 }
360 if ( isset( $wizard_settings['thirdparty_scripts'] ) ) {
361 $custom_scripts['thirdparty_scripts'] = $wizard_settings['thirdparty_scripts'];
362 }
363 if ( isset( $wizard_settings['thirdparty_iframes'] ) ) {
364 $custom_scripts['thirdparty_iframes'] = $wizard_settings['thirdparty_iframes'];
365 }
366 unset( $wizard_settings['statistics_script'] );
367 unset( $wizard_settings['cookie_scripts'] );
368 unset( $wizard_settings['cookie_scripts_async'] );
369 unset( $wizard_settings['thirdparty_scripts'] );
370 unset( $wizard_settings['thirdparty_iframes'] );
371 update_option( 'complianz_options_custom-scripts', $custom_scripts );
372 update_option( 'complianz_options_wizard', $wizard_settings );
373
374 /**
375 * we dismiss the integrations enabled notices
376 */
377
378 $dismissed_warnings = get_option( 'cmplz_dismissed_warnings', array() );
379 $fields = COMPLIANZ::$config->fields( 'integrations' );
380 foreach ( $fields as $warning_id => $field ) {
381 if ( $field['disabled'] ) {
382 continue;
383 }
384 if ( ! in_array( $warning_id, $dismissed_warnings ) ) {
385 $dismissed_warnings[] = $warning_id;
386 }
387 }
388 update_option( 'cmplz_dismissed_warnings', $dismissed_warnings, false );
389 }
390
391 if ( $prev_version && version_compare( $prev_version, '5.1.0', '<' ) ) {
392 update_option( 'cmplz_first_version', '5.0.0', false );
393 }
394
395 /**
396 * restore dropshadow in TCF banner.
397 */
398 if ( $prev_version
399 && version_compare( $prev_version, '5.1.2', '<' )
400 ) {
401 if ( cmplz_tcf_active() ) {
402 $banners = cmplz_get_cookiebanners();
403 if ( $banners ) {
404 foreach ( $banners as $banner_item ) {
405 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID, false );
406 $banner->use_box_shadow = true;
407 $banner->save();
408 }
409 }
410 }
411 }
412
413 if ( $prev_version
414 && version_compare( $prev_version, '5.2.0', '<' )
415 ) {
416 if ( cmplz_tcf_active() ) {
417 $banners = cmplz_get_cookiebanners();
418 if ( $banners ) {
419 foreach ( $banners as $banner_item ) {
420 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID, false );
421 $banner->colorpalette_button_accept = array(
422 'background' => '#333',
423 'border' => '#333',
424 'text' => '#fff',
425 );
426 $banner->colorpalette_button_settings = array(
427 'background' => '#fff',
428 'border' => '#333',
429 'text' => '#333',
430 );
431 $banner->save();
432 }
433 }
434 }
435 }
436
437 if ( $prev_version
438 && version_compare( $prev_version, '5.2.6.1', '<' )
439 ) {
440 if ( cmplz_tcf_active() ) {
441 delete_option( 'cmplz_vendorlist_downloaded_once' );
442 }
443 }
444
445 /**
446 * Change metakeys for eu dataleaks from '{metakey}' to '{metakey}-eu' for consistency between dataleaks .
447 */
448 if ( $prev_version
449 && version_compare( $prev_version, '5.4.0', '<' )
450 ) {
451 $args = array(
452 'numberposts' => - 1,
453 'post_type' => 'cmplz-dataleak',
454 'tax_query' => array(
455 array(
456 'taxonomy' => 'cmplz-region',
457 'field' => 'slug',
458 'terms' => 'eu',
459 ),
460 ),
461 );
462
463 $posts = get_posts( $args );
464 $meta_keys = array(
465 'security-incident-occurred',
466 'type-of-dataloss',
467 'reach-of-dataloss',
468 'risk-of-data-loss',
469 'what-occurred',
470 'consequences',
471 'measures',
472 'measures_by_person_involved',
473 'conclusion',
474 );
475 foreach ( $posts as $post ) {
476 foreach ( $meta_keys as $meta_key ) {
477 $value = get_post_meta( $post->ID, $meta_key, true );
478 if ( $value ) {
479 update_post_meta( $post->ID, $meta_key . '-eu', $value );
480 }
481 }
482 }
483
484 $wizard_settings = get_option( 'complianz_options_wizard' );
485 //upgrade to checkboxes structure.
486 $value_eu = $value_uk = false;
487 if ( isset( $wizard_settings['dpo_or_gdpr'] ) ) {
488 $value_eu = $wizard_settings['dpo_or_gdpr'];
489 }
490
491 if ( isset( $wizard_settings['dpo_or_uk_gdpr'] ) ) {
492 $value_uk = $wizard_settings['dpo_or_uk_gdpr'];
493 }
494 if ( ! is_array( $value_eu ) ) {
495 $new_value = array(
496 'dpo' => 0,
497 'dpo_uk' => 0,
498 'gdpr_rep' => 0,
499 'uk_gdpr_rep' => 0,
500 );
501 if ( $value_eu ) {
502 $new_value[ $value_eu ] = 1;
503 }
504 if ( $value_uk ) {
505 if ( $value_uk === 'dpo' ) {
506 $value_uk = 'dpo_uk';
507 }
508 $new_value[ $value_uk ] = 1;
509 }
510 //none is not applicable anymore, as it's multischeckbox
511 unset( $new_value['none'] );
512
513 $wizard_settings['dpo_or_gdpr'] = $new_value;
514 unset( $wizard_settings['dpo_or_uk_gdpr'] );
515
516 if ( isset( $wizard_settings['ca_name_address_accountable_person'] ) ) {
517 $address = preg_split( '#\n(?!s)#', $wizard_settings['ca_name_address_accountable_person'] );
518 $name = isset( $address[0] ) ? $address[0] : '';
519 unset( $address[0] );
520 $address = implode( "\n", $address );
521 $wizard_settings['ca_name_accountable_person'] = $name;
522 $wizard_settings['ca_address_accountable_person'] = $address;
523 }
524
525 update_option( 'complianz_options_wizard', $wizard_settings );
526 }
527 }
528
529 if ( $prev_version
530 && version_compare( $prev_version, '5.5.0', '<' )
531 ) {
532 $wizard_settings = get_option( 'complianz_options_wizard' );
533 $settings_settings = get_option( 'complianz_options_settings' );
534 if ( isset( $wizard_settings['use_cdb_api'] ) ) {
535 $settings_settings['use_cdb_api'] = $wizard_settings['use_cdb_api'];
536 $settings_settings['use_cdb_links'] = $wizard_settings['use_cdb_links'];
537 }
538 unset( $wizard_settings['use_cdb_api'] );
539 unset( $wizard_settings['use_cdb_links'] );
540 update_option( 'complianz_options_wizard', $wizard_settings );
541 update_option( 'complianz_options_settings', $settings_settings );
542 }
543
544 if ( $prev_version
545 && version_compare( $prev_version, '5.5.0', '<' )
546 ) {
547 $wizard_settings = get_option( 'complianz_options_wizard' );
548
549 $share_data_us = $share_data_eu = 2;
550 if ( isset($wizard_settings['share_data_other_us']) ) {
551 $share_data_us = intval($wizard_settings['share_data_other_us']);
552 }
553 if ( isset($wizard_settings['share_data_other']) ) {
554 $share_data_eu = intval($wizard_settings['share_data_other']);
555 }
556 //share data other parties: indien een van beide "yes", nieuwe yes. Indien een van beide limited, nieuwe "limited". anders no.
557 if ($share_data_us===1 || $share_data_eu ===1) {
558 $share_data = 1;
559 } else if ($share_data_us===3 || $share_data_eu ===3){
560 $share_data = 3;
561 } else {
562 $share_data = 2;
563 }
564 $wizard_settings['share_data_other'] = $share_data;
565 $us_processors = isset($wizard_settings['processor_us'] ) ? $wizard_settings['processor_us'] : array();
566 $eu_processors = isset($wizard_settings['processor']) ? $wizard_settings['processor'] : array();
567 foreach ( $us_processors as $us_processor ) {
568 //check if it's already in the list
569 $key = array_search($us_processor['name'], array_column($eu_processors, 'name'));
570 if ( $key !== false ) unset($us_processors[ $key ]);
571 }
572
573 //now add the remaining values to the EU list
574 $eu_processors = array_merge($eu_processors, $us_processors);
575 $wizard_settings['processor'] = $eu_processors;
576
577 $us_thirdparties = isset($wizard_settings['thirdparty_us'] ) ? $wizard_settings['thirdparty_us'] : array();
578 $eu_thirdparties = isset($wizard_settings['thirdparty']) ? $wizard_settings['thirdparty'] : array();
579 foreach ( $us_thirdparties as $us_thirdparty ) {
580 //check if it's already in the list
581 $key = array_search($us_thirdparty['name'], array_column($eu_thirdparties, 'name'));
582 if ( $key !== false ) unset($us_thirdparties[ $key ]);
583 }
584 //now add the remaining values to the EU list
585 $eu_thirdparties = array_merge($eu_thirdparties, $us_thirdparties);
586 $wizard_settings['thirdparty'] = $eu_thirdparties;
587 unset($wizard_settings['thirdparty_us']);
588 unset($wizard_settings['processor_us']);
589
590 update_option( 'complianz_options_wizard', $wizard_settings );
591 }
592
593 if ( $prev_version && version_compare( $prev_version, '6.0.0', '<' ) ) {
594 $custom_scripts = get_option( 'complianz_options_custom-scripts' );
595
596 $scripts['add_script'] = [];
597 $scripts['block_script'] = [];
598 $scripts['whitelist_script'] = [];
599
600 if ( ! empty( $custom_scripts['cookie_scripts'] ) ) {
601 $scripts['add_script'][] = [
602 'name' => 'Scripts',
603 'editor' => $custom_scripts['cookie_scripts'],
604 'async' => '0',
605 'category' => 'marketing',
606 'enable_placeholder' => '0',
607 'placeholder_class' => '',
608 'placeholder' => '',
609 'enable_dependency' => '0',
610 'dependency' => '',
611 'enable' => '1',
612 ];
613 }
614
615 if ( ! empty( $custom_scripts['cookie_scripts_async'] ) ) {
616 $scripts['add_script'][] = [
617 'name' => 'Async scripts',
618 'editor' => $custom_scripts['cookie_scripts_async'],
619 'async' => '1',
620 'category' => 'marketing',
621 'enable_placeholder' => '0',
622 'placeholder_class' => '',
623 'placeholder' => '',
624 'enable_dependency' => '0',
625 'dependency' => '',
626 'enable' => '1',
627 ];
628 }
629
630 if ( ! empty( $custom_scripts['statistics_script'] ) ) {
631 $scripts['add_script'][] = [
632 'name' => 'Statistics scripts',
633 'editor' => $custom_scripts['statistics_script'],
634 'async' => '0',
635 'category' => 'statistics',
636 'enable_placeholder' => '0',
637 'placeholder_class' => '',
638 'placeholder' => '',
639 'enable_dependency' => '0',
640 'dependency' => '',
641 'enable' => '1',
642 ];
643 }
644
645 if ( ! empty( $custom_scripts['thirdparty_scripts'] ) ) {
646 $scripts['block_script'][] = [
647 'name' => 'Third party scripts',
648 'urls' => explode( ',', $custom_scripts['thirdparty_scripts'] ),
649 'category' => 'marketing',
650 'enable_placeholder' => '0',
651 'placeholder_class' => '',
652 'placeholder' => '',
653 'enable' => '1',
654 ];
655 }
656
657 if ( ! empty( $custom_scripts['thirdparty_iframes'] ) ) {
658 $scripts['block_script'][] = [
659 'name' => 'Third party iframes',
660 'urls' => explode( ',', $custom_scripts['thirdparty_iframes'] ),
661 'category' => 'marketing',
662 'enable_placeholder' => '0',
663 'placeholder_class' => '',
664 'placeholder' => '',
665 'enable' => '1',
666 ];
667 }
668 update_option( 'complianz_options_custom-scripts', $scripts );
669
670 $general_settings = get_option( 'complianz_options_settings' );
671 $general_settings['enable_migrate_js'] = true;
672 update_option( 'complianz_options_settings', $general_settings );
673
674 $banners = cmplz_get_cookiebanners();
675 if ( $banners ) {
676 foreach ( $banners as $banner_item ) {
677 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
678 switch ( $banner->use_categories ) {
679 case 'no':
680 $banner->use_categories = 'no';
681 break;
682 case 'legacy':
683 case 'visible':
684 $banner->use_categories = 'save-preferences';
685 break;
686 default:
687 $banner->use_categories = 'view-preferences';
688 }
689
690 switch ( $banner->position ) {
691 case 'top':
692 $banner->position = 'bottom';
693 break;
694 case 'bottom':
695 case 'bottom-left':
696 case 'bottom-right':
697 break;
698 default:
699 $banner->position = 'center';
700 }
701
702 switch ( $banner->checkbox_style ) {
703 case 'classic':
704 $banner->checkbox_style = 'classic';
705 break;
706 default:
707 $banner->checkbox_style = 'slider';
708 }
709
710 if ( !is_serialized($banner->border_width) ) {
711 $banner->border_width = array(
712 'top' => 0,
713 'right' => 0,
714 'bottom' => 0,
715 'left' => 0,
716 );
717 }
718
719 if ( !isset($banner->border_width['top']) ) $banner->border_width['top'] = 0;
720 if ( !isset($banner->border_width['right']) ) $banner->border_width['right'] = 0;
721 if ( !isset($banner->border_width['bottom']) ) $banner->border_width['bottom'] = 0;
722 if ( !isset($banner->border_width['left']) ) $banner->border_width['left'] = 0;
723
724 if (!is_serialized($banner_item->dismiss)) {
725 $banner->revoke = array(
726 'text' => $banner_item->revoke,
727 'show' => ! $banner_item->hide_revoke,
728 );
729 }
730
731 if (!is_serialized($banner_item->header) ) {
732 if ( strlen($banner_item->header)<4 ) {
733 $banner->header = array(
734 'text' => '',
735 'show' => false,
736 );
737 } else {
738 $banner->header = array(
739 'text' => $banner_item->header,
740 'show' => true,
741 );
742 }
743 }
744
745 if (!is_serialized($banner_item->accept_informational)) {
746 $banner->accept_informational = array(
747 'text' => $banner_item->accept_informational,
748 'show' => true,
749 );
750 }
751
752 if (!is_serialized($banner_item->category_prefs)) {
753 $banner->category_prefs = array(
754 'text' => $banner_item->category_prefs,
755 'show' => true,
756 );
757 }
758
759 if (!is_serialized($banner_item->category_stats)) {
760 $banner->category_stats = array(
761 'text' => $banner_item->category_stats,
762 'show' => true,
763 );
764 }
765
766 if (!is_serialized($banner_item->category_all)) {
767 $banner->category_all = array(
768 'text' => $banner_item->category_all,
769 'show' => true,
770 );
771 }
772
773 $banner->use_box_shadow = true;
774 $banner->use_logo = 'hide';
775 $banner->close_button = false;
776 $banner->save();
777 }
778 }
779
780 $wizard_settings = get_option( 'complianz_options_wizard' );
781 if ( isset( $wizard_settings['compile_statistics'] ) && $wizard_settings['compile_statistics'] === 'yes-anonymous' ) {
782 $wizard_settings['compile_statistics'] = 'yes';
783 update_option( 'complianz_options_wizard', $wizard_settings );
784 }
785 }
786
787 if ( $prev_version && version_compare( $prev_version, '6.0.0', '>=' ) ) {
788 $warning_id = 'upgraded_to_6';
789 $dismissed_warnings = get_option( 'cmplz_dismissed_warnings', array() );
790 if ( !in_array($warning_id, $dismissed_warnings) ) {
791 $dismissed_warnings[] = $warning_id;
792 update_option('cmplz_dismissed_warnings', $dismissed_warnings );
793 delete_transient('complianz_warnings');
794 delete_transient('complianz_warnings_admin_notices');
795 }
796 }
797
798 if ( $prev_version && version_compare( $prev_version, '6.0.2', '<' ) ) {
799 $banners = cmplz_get_cookiebanners();
800 if ( $banners ) {
801 foreach ( $banners as $banner_item ) {
802 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
803 if ( $banner->banner_width == 476 ) {
804 $banner->banner_width = 526;
805 $banner->save();
806 }
807 }
808 }
809 }
810 if ( $prev_version && version_compare( $prev_version, '6.0.5', '<' ) ) {
811 update_option('complianz_enable_dismissible_premium_warnings', true);
812 }
813
814 if ( $prev_version && version_compare( $prev_version, '6.0.8', '<' ) ) {
815 $banners = cmplz_get_cookiebanners();
816 if ( $banners ) {
817 foreach ( $banners as $banner_item ) {
818 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
819 if ( $banner->use_categories === 'hidden' ) {
820 $banner->use_categories = 'view-preferences';
821 $banner->save();
822 }
823 }
824 }
825 }
826
827 if ( $prev_version && version_compare( $prev_version, '6.0.4', '<' ) ) {
828 update_option( 'cmplz_vendorlist_downloaded_once', strtotime('-1 week') + HOUR_IN_SECONDS, false );
829 }
830
831 if ( $prev_version && version_compare( $prev_version, '6.1.0', '<' ) ) {
832 $banners = cmplz_get_cookiebanners();
833 if ( $banners ) {
834 foreach ( $banners as $banner_item ) {
835 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
836 $banner->legal_documents = true;
837 $banner->save();
838 }
839 }
840 }
841
842 if ( $prev_version && version_compare( $prev_version, '6.1.4.1', '<' ) ) {
843 $wizard_settings = get_option( 'complianz_options_wizard' );
844 if ( isset( $wizard_settings['create_banner_elementor'] ) ) {
845 if ($wizard_settings['create_banner_elementor']==='yes' ) {
846 update_option('cmplz_elementor_banner_dropped', true);
847 }
848 $wizard_settings['create_banner_elementor'] = 'no';
849 update_option( 'complianz_options_wizard', $wizard_settings );
850 $post_id = get_option('cmplz_elementor_autogenerated' );
851 $args = array(
852 'post_status' => 'draft',
853 'ID' => $post_id,
854 );
855 wp_update_post($args);
856 }
857 }
858
859 if ( $prev_version && version_compare( $prev_version, '6.2.2', '<' ) ) {
860 $wizard_settings = get_option( 'complianz_options_wizard' );
861 if ( isset( $wizard_settings['data_request_forms'] ) ) {
862 $wizard_settings['datarequest'] = $wizard_settings['data_request_forms'];
863 unset($wizard_settings['data_request_forms']);
864 update_option( 'complianz_options_wizard', $wizard_settings );
865 }
866 }
867
868 // 6.3 United States Upgrade
869 if ( $prev_version && version_compare( $prev_version, '6.3.0', '<' ) ) {
870 $wizard_settings = get_option( 'complianz_options_wizard' );
871 if ( isset( $wizard_settings['california'] ) && $wizard_settings['california'] === 'yes' ) {
872 unset( $wizard_settings['california'] );
873 $wizard_settings['us_states']['cal'] = 1;
874 }
875
876 $mapping_array = [
877 '1' => [ 'first-lastname', 'address' ],
878 '2' => [ 'marital-status' ],
879 '5' => [ 'date-of-birth' ],
880 '6' => [ 'accountname-alias' ],
881 '7' => [ 'sex' ],
882 '3' => [ 'email' ],
883 '15' => [ 'phone' ],
884 '8' => [ 'ip' ],
885 '4' => [ 'financial-information' ],
886 '10' => [ 'medical' ],
887 '11' => [ 'internet' ],
888 '9' => [ 'geo' ],
889 '12' => [ 'photos' ],
890 '13' => [ 'social-media' ],
891 '14' => [ 'criminal' ],
892 ];
893 foreach ( COMPLIANZ::$config->purposes as $key => $label ) {
894 if ( !isset($wizard_settings[$key . '_retain_data']) ) {
895 $wizard_settings[$key . '_retain_data'] = '1';
896 }
897
898 if (isset($wizard_settings[$key . '_data_purpose']) ) {
899 $values = $wizard_settings[$key . '_data_purpose'];
900 foreach ($values as $value => $enabled) {
901 $enabled = $enabled==='1';
902 if ( $enabled && isset($mapping_array[ $value ])) {
903 $new_values = $mapping_array[ $value ];
904 foreach ($new_values as $new_value ) {
905 $wizard_settings[$key . '_data_purpose_us'][$new_value] = 1;
906 }
907 }
908 }
909 unset($wizard_settings[$key . '_data_purpose']);
910 }
911 if ( isset($wizard_settings[$key . '_data_purpose_us'] ) ) {
912 $values = $wizard_settings[$key . '_data_purpose_us'];
913 foreach ($values as $value => $enabled) {
914 $enabled = $enabled==='1';
915 if ($enabled && $value === 'any-other') {
916 unset($wizard_settings[$key . '_data_purpose_us'][$value]);
917 }
918 }
919 }
920 }
921 update_option( 'complianz_options_wizard', $wizard_settings );
922
923 $banners = cmplz_get_cookiebanners();
924 if ( $banners ) {
925 foreach ( $banners as $banner_item ) {
926 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
927 $revoke = $banner_item->revoke;
928 if ( is_serialized( $revoke ) ) {
929 $revoke = unserialize( $revoke );
930 }
931 if ( isset( $revoke['text'] ) ) {
932 $banner->revoke = $revoke['text'];
933 }
934 if ( isset( $revoke['show'] ) ) {
935 if ( $revoke['show'] == '1' ) {
936 $banner->manage_consent_options = 'hover-hide-mobile';
937 } else {
938 $banner->manage_consent_options = 'hide-everywhere';
939 }
940 }
941 $banner->save();
942 }
943 }
944 }
945
946 if ( $prev_version && version_compare( $prev_version, '6.3.2', '<' ) ) {
947 //upgrade statistics a/b testing
948 $general_settings = get_option( 'complianz_options_settings' );
949 if ( isset( $general_settings['a_b_testing'] ) && $general_settings['a_b_testing'] ) {
950 $general_settings['a_b_testing_buttons'] = true;
951 }
952 update_option( 'complianz_options_settings', $general_settings );
953 }
954
955 if ( $prev_version && version_compare( $prev_version, '6.3.7', '<' ) ) {
956 $wizard_settings = get_option( 'complianz_options_wizard', [] );
957 $wizard_settings['enable_cookie_banner']='yes';
958 $wizard_settings['enable_cookie_blocker']='yes';
959 update_option( 'complianz_options_wizard', $wizard_settings );
960
961 $settings = get_option( 'complianz_options_settings', [] );
962 $settings['safe_mode'] = $settings['disable_cookie_block'] ?? false;
963 if ( isset($settings['disable_cookie_block']) ) {
964 unset($settings['disable_cookie_block']);
965 }
966 update_option( 'complianz_options_settings', $settings );
967 }
968
969
970 //ensure new capability
971 if ( $prev_version && version_compare( $prev_version, '6.4.1', '<' ) ) {
972 cmplz_add_manage_privacy_capability();
973 }
974
975 //update for TCF GVL 3
976 //regenerate css
977 //set manage consent tab
978 if ( $prev_version && version_compare( $prev_version, '6.5.4', '<' ) ) {
979 update_option('cmplz_completed_upgrade_with_condition', true, false);
980 if ( cmplz_tcf_active() ) {
981 $banners = cmplz_get_cookiebanners();
982 if ( $banners ) {
983 foreach ( $banners as $banner_item ) {
984 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
985 $banner->save();
986 }
987 }
988 }
989 }
990
991 if ( $prev_version && version_compare( $prev_version, '6.5.4', '=' ) ) {
992 //if the previous update already was executed without the TCF condition, put it back to default.
993 //this is the case for prev_version = 6.5.4 and not free
994 if ( !get_option('cmplz_completed_upgrade_with_condition') && !defined('cmplz_free') && !cmplz_tcf_active() ){
995 $banners = cmplz_get_cookiebanners();
996 if ( $banners ) {
997 foreach ( $banners as $banner_item ) {
998 $banner = new CMPLZ_COOKIEBANNER( $banner_item->ID );
999 $banner->manage_consent_options = 'hover-hide-mobile';
1000 $banner->save();
1001 }
1002 }
1003 }
1004 delete_option('cmplz_completed_upgrade_with_condition');
1005 }
1006
1007 #regenerate cookie policy snapshot.
1008 update_option('cmplz_generate_new_cookiepolicy_snapshot', true, false);
1009 //always clear warnings cache on update
1010 delete_transient('complianz_warnings');
1011 delete_transient('complianz_warnings_admin_notices');
1012 do_action( 'cmplz_upgrade', $prev_version );
1013 update_option( 'cmplz-current-version', cmplz_version, false );
1014 }
1015