-
Notifications
You must be signed in to change notification settings - Fork 13
/
social-media-category.php
106 lines (90 loc) · 4.17 KB
/
social-media-category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
function cmplz_add_social_media_category($html){
$pattern = '/<details class="cmplz-category cmplz-marketing.*?<\/details>/is';
ob_start();
?>
<details class="cmplz-category cmplz-socialmedia">
<summary>
<div class="cmplz-category-header">
<div class="cmplz-category-title"><?php _e("Social media", "complianz-gdpr")?></div>
<div class="cmplz-banner-checkbox">
<input type="checkbox" id="cmplz-socialmedia-optin" data-category="cmplz_socialmedia" class="cmplz-consent-checkbox cmplz-socialmedia" size="40" value="1">
<label class="cmplz-label" for="cmplz-socialmedia-optin" tabindex="0"><span>
<?php _e("Social media", "complianz-gdpr")?></span></label>
</div>
<div class="cmplz-icon cmplz-open"></div>
</div>
</summary>
<div class="cmplz-description">
<span class="cmplz-description-socialmedia">
// Social Media descriptive text
<?php _e("The technical storage or access is required to create user profiles to send advertising,
or to track the user on a website or across several websites for similar marketing purposes.", "complianz-gdpr")?></span>
</div>
</details>
<?php
$social = ob_get_clean();
if ( preg_match( $pattern, $html, $matches ) ) {
$marketing = $matches[0];
$html = str_replace($marketing, $social.$marketing, $html);
}
return $html;
}
add_filter('cmplz_banner_html', 'cmplz_add_social_media_category');
function cmplz_social_media_script() {
ob_start();
?>
<script>
document.addEventListener('click', e => {
if ( e.target.closest('.cmplz-save-preferences') ) {
let social_media_enabled = document.querySelector('input.cmplz-socialmedia').checked;
if (social_media_enabled) {
// remove or add services below if needed
//if any service is enabled, allow the general services also, because some services are partially 'general'
let services = ['facebook', 'instagram', 'whatsapp', 'tiktok', 'pinterest', 'linkedin', 'twitter', 'disqus'];
cmplz_enable_category('', 'general');
for (let key in services) {
if (services.hasOwnProperty(key)) {
let service = services[key];
console.log("enable " + service);
if (service.length == 0) continue;
cmplz_set_service_consent(service, true);
cmplz_enable_category('', service);
document.querySelectorAll('.cmplz-accept-service[data-service=' + service + ']').forEach(obj => {
obj.checked = true;
});
}
}
cmplz_set_cookie('socialmedia', 'allow');
}
}
});
document.addEventListener("cmplz_before_cookiebanner", function(e) {
if (cmplz_get_cookie('socialmedia') === 'allow'){
document.querySelector('input.cmplz-socialmedia').checked = true;
}
});
document.addEventListener("cmplz_fire_categories", function (e) {
var consentedCategories = e.detail.categories;
if ( cmplz_in_array( 'socialmedia', consentedCategories ) ) {
if (cmplz_fired_events.indexOf('socialmedia') === -1) {
cmplz_fired_events.push('socialmedia');
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': complianz.prefix+'event_socialmedia'
});
let event = new CustomEvent('cmplz_tag_manager_event', { detail: 'socialmedia' });
document.dispatchEvent(event);
}
}
});
document.addEventListener("cmplz_revoke", function(e) {
cmplz_set_cookie('socialmedia', 'deny');
});
</script>
<?php
$script = ob_get_clean();
$script = str_replace(array('<script>', '</script>'), '', $script);
wp_add_inline_script( 'cmplz-cookiebanner', $script );
}
add_action( 'wp_enqueue_scripts', 'cmplz_social_media_script',PHP_INT_MAX );