-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCookieConsent.php
More file actions
82 lines (71 loc) · 2.18 KB
/
Copy pathCookieConsent.php
File metadata and controls
82 lines (71 loc) · 2.18 KB
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
<?php
namespace Municipio\Helper;
class CookieConsent
{
private static bool|array $cookieConsent;
/**
* Get the cookie consents from the Pressidium plugin.
*
* @return array|false The consents or false if not set.
*/
public static function getConsents()
{
if (self::pressidiumIsEnabled()) {
$consents = isset($_COOKIE['pressidium_cookie_consent'])
? json_decode(stripslashes($_COOKIE['pressidium_cookie_consent']), true)
: [];
return self::parsePressidiumConsents($consents);
}
return false;
}
/**
* Check if the required consents are present.
*
* @param array $requiredConsents The required consents.
* @return bool True if all required consents are present, false otherwise.
*/
public static function hasConsents(array $requiredConsents)
{
if (!isset(self::$cookieConsent)) {
self::$cookieConsent = self::getConsents();
}
if (self::$cookieConsent === false) {
return true;
}
foreach ($requiredConsents as $type) {
if (!isset(self::$cookieConsent[$type]) || !self::$cookieConsent[$type]) {
return false;
}
}
return true;
}
/**
* Check if the Pressidium cookie consent plugin is enabled.
*
* @return bool True if the plugin is enabled, false otherwise.
*/
public static function pressidiumIsEnabled()
{
return class_exists('Pressidium\WP\CookieConsent\Plugin')
&& is_plugin_active('pressidium-cookie-consent/pressidium-cookie-consent.php');
}
/**
* Parse the Pressidium cookie consent data.
*
* @param array $data The cookie consent data.
* @return array The parsed consents.
*/
private static function parsePressidiumConsents($data)
{
$consents = [
'necessary' => false,
'preferences' => false,
'analytics' => false,
'targeting' => false,
];
foreach ($data['categories'] as $type) {
$consents[$type] = true;
}
return $consents;
}
}