buffer
3 years ago
script_loader_tag
3 years ago
traits
3 years ago
Consent_API_Helper.php
3 years ago
Cookie_Consent.php
3 years ago
Cookie_Consent_Interface.php
4 years ago
Cookiebot_Activated.php
3 years ago
Cookiebot_Automatic_Updates.php
3 years ago
Cookiebot_Deactivated.php
4 years ago
Cookiebot_Javascript_Helper.php
3 years ago
Cookiebot_WP.php
3 years ago
Dependency_Container.php
3 years ago
Settings_Page_Tab.php
3 years ago
Settings_Service.php
3 years ago
Settings_Service_Interface.php
3 years ago
Supported_Languages.php
4 years ago
Supported_Regions.php
3 years ago
WP_Rocket_Helper.php
3 years ago
Widgets.php
3 years ago
global-deprecations.php
3 years ago
helper.php
3 years ago
Consent_API_Helper.php
144 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | |
| 7 | class Consent_API_Helper { |
| 8 | public function register_hooks() { |
| 9 | // Include integration to WP Consent Level API if available |
| 10 | if ( $this->is_wp_consent_api_active() ) { |
| 11 | add_action( 'wp_enqueue_scripts', array( $this, 'cookiebot_enqueue_consent_api_scripts' ) ); |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Cookiebot_WP Check if WP Cookie Consent API is active |
| 17 | * |
| 18 | * @version 3.5.0 |
| 19 | * @since 3.5.0 |
| 20 | */ |
| 21 | public function is_wp_consent_api_active() { |
| 22 | return class_exists( 'WP_CONSENT_API' ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Cookiebot_WP Enqueue JS for integration with WP Consent Level API |
| 27 | * |
| 28 | * @throws InvalidArgumentException |
| 29 | * @since 3.5.0 |
| 30 | * @version 3.5.0 |
| 31 | */ |
| 32 | public function cookiebot_enqueue_consent_api_scripts() { |
| 33 | wp_register_script( |
| 34 | 'cookiebot-wp-consent-level-api-integration', |
| 35 | asset_url( 'js/frontend/cookiebot-wp-consent-level-api-integration.js' ), |
| 36 | null, |
| 37 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 38 | false |
| 39 | ); |
| 40 | wp_enqueue_script( 'cookiebot-wp-consent-level-api-integration' ); |
| 41 | wp_localize_script( |
| 42 | 'cookiebot-wp-consent-level-api-integration', |
| 43 | 'cookiebot_category_mapping', |
| 44 | $this->get_wp_consent_api_mapping() |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Cookiebot_WP Get the mapping between Consent Level API and Cookiebot |
| 50 | * Returns array where key is the consent level api category and value |
| 51 | * is the mapped Cookiebot category. |
| 52 | * |
| 53 | * @version 3.5.0 |
| 54 | * @since 3.5.0 |
| 55 | */ |
| 56 | public function get_wp_consent_api_mapping() { |
| 57 | $default_wp_consent_api_mapping = $this->get_default_wp_consent_api_mapping(); |
| 58 | $mapping = get_option( 'cookiebot-consent-mapping', $default_wp_consent_api_mapping ); |
| 59 | |
| 60 | $mapping = ( '' === $mapping ) ? $default_wp_consent_api_mapping : $mapping; |
| 61 | |
| 62 | foreach ( $default_wp_consent_api_mapping as $k => $v ) { |
| 63 | if ( ! isset( $mapping[ $k ] ) ) { |
| 64 | $mapping[ $k ] = $v; |
| 65 | } else { |
| 66 | foreach ( $v as $vck => $vcv ) { |
| 67 | if ( ! isset( $mapping[ $k ][ $vck ] ) ) { |
| 68 | $mapping[ $k ][ $vck ] = $vcv; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return $mapping; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Cookiebot_WP Default consent level mappings |
| 79 | * |
| 80 | * @version 3.5.0 |
| 81 | * @since 3.5.0 |
| 82 | */ |
| 83 | public function get_default_wp_consent_api_mapping() { |
| 84 | return array( |
| 85 | 'n=1;p=1;s=1;m=1' => |
| 86 | array( |
| 87 | 'preferences' => 1, |
| 88 | 'statistics' => 1, |
| 89 | 'statistics-anonymous' => 0, |
| 90 | 'marketing' => 1, |
| 91 | ), |
| 92 | 'n=1;p=1;s=1;m=0' => |
| 93 | array( |
| 94 | 'preferences' => 1, |
| 95 | 'statistics' => 1, |
| 96 | 'statistics-anonymous' => 1, |
| 97 | 'marketing' => 0, |
| 98 | ), |
| 99 | 'n=1;p=1;s=0;m=1' => |
| 100 | array( |
| 101 | 'preferences' => 1, |
| 102 | 'statistics' => 0, |
| 103 | 'statistics-anonymous' => 0, |
| 104 | 'marketing' => 1, |
| 105 | ), |
| 106 | 'n=1;p=1;s=0;m=0' => |
| 107 | array( |
| 108 | 'preferences' => 1, |
| 109 | 'statistics' => 0, |
| 110 | 'statistics-anonymous' => 0, |
| 111 | 'marketing' => 0, |
| 112 | ), |
| 113 | 'n=1;p=0;s=1;m=1' => |
| 114 | array( |
| 115 | 'preferences' => 0, |
| 116 | 'statistics' => 1, |
| 117 | 'statistics-anonymous' => 0, |
| 118 | 'marketing' => 1, |
| 119 | ), |
| 120 | 'n=1;p=0;s=1;m=0' => |
| 121 | array( |
| 122 | 'preferences' => 0, |
| 123 | 'statistics' => 1, |
| 124 | 'statistics-anonymous' => 0, |
| 125 | 'marketing' => 0, |
| 126 | ), |
| 127 | 'n=1;p=0;s=0;m=1' => |
| 128 | array( |
| 129 | 'preferences' => 0, |
| 130 | 'statistics' => 0, |
| 131 | 'statistics-anonymous' => 0, |
| 132 | 'marketing' => 1, |
| 133 | ), |
| 134 | 'n=1;p=0;s=0;m=0' => |
| 135 | array( |
| 136 | 'preferences' => 0, |
| 137 | 'statistics' => 0, |
| 138 | 'statistics-anonymous' => 0, |
| 139 | 'marketing' => 0, |
| 140 | ), |
| 141 | ); |
| 142 | } |
| 143 | } |
| 144 |