From 2396a4f1bcfcb3bd824d0cc44f729061187b01c6 Mon Sep 17 00:00:00 2001 From: Antonio Pinto Date: Tue, 27 Jan 2026 11:54:57 +0000 Subject: [PATCH] Fix: prepare v4.6.3 --- cookiebot.php | 2 +- readme.txt | 15 ++++- src/lib/Cookiebot_Activated.php | 8 +++ src/lib/Cookiebot_Deactivated.php | 1 - src/lib/Cookiebot_WP.php | 2 +- .../script_loader_tag/Script_Loader_Tag.php | 56 ++++++++++++++++++- 6 files changed, 77 insertions(+), 7 deletions(-) diff --git a/cookiebot.php b/cookiebot.php index 094b8282..3e5bdc2c 100644 --- a/cookiebot.php +++ b/cookiebot.php @@ -5,7 +5,7 @@ Plugin URI: https://www.cookiebot.com/ Description: Install your cookie banner in minutes. Automatically scan and block cookies to comply with the GDPR, CCPA, Google Consent Mode v2. Free plan option. Author: Usercentrics A/S -Version: 4.6.2 +Version: 4.6.3 Author URI: https://www.cookiebot.com/ Text Domain: cookiebot Domain Path: /langs diff --git a/readme.txt b/readme.txt index 368eca40..5fe6f26a 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ * Tags: cookie banner, cookie consent, cookie notice, GDPR, privacy, cmp, consent‑management‑platform, google‑consent‑mode, compliance, gdpr‑compliance, ccpa, dma * Requires at least: 4.4 * Tested up to: 6.8 -* Stable tag: 4.6.2 +* Stable tag: 4.6.3 * Requires PHP: 5.6 * License: GPLv2 or later @@ -163,6 +163,19 @@ Usercentrics Cookiebot is fully integrated with the WP Consent API. When your vi ## Changelog ## **Cookiebot by Usercentrics Plugin will soon no longer support PHP 5. If your website still runs on this version we recommend upgrading so you can continue enjoying the features Cookiebot by Usercentrics offers.** +### 4.6.3 ### +Release date: January 27th 2026 + +Cookiebot by Usercentrics version 4.6.3 is out! This release has a bugfix and an improvement + +####Improvements#### + +* Enhanced script consent handling for WordPress 5.7+, including proper support for inline scripts + +####Bugfixes#### + +* Fixed an issue where the consent banner could become disabled after plugin updates or hosting migrations + ### 4.6.2 ### Release date: December 17th 2025 diff --git a/src/lib/Cookiebot_Activated.php b/src/lib/Cookiebot_Activated.php index b1fbdf4f..0314bbf3 100644 --- a/src/lib/Cookiebot_Activated.php +++ b/src/lib/Cookiebot_Activated.php @@ -86,10 +86,18 @@ private function set_to_mode_auto_when_no_cookiebot_id_is_set() { private function set_banner_enabled_by_default() { $enabled = get_option( 'cookiebot-banner-enabled', 'default' ); + $cbid = Cookiebot_WP::get_cbid(); + + // Set to enabled if it's a fresh install (default) if ( $enabled === 'default' ) { $enabled = '1'; update_option( 'cookiebot-banner-enabled', $enabled ); } + + // If banner is disabled but CBID is configured, it was disabled by hosting or plugin update. Re-enable it. + if ( $enabled === '0' && ! empty( $cbid ) ) { + update_option( 'cookiebot-banner-enabled', '1' ); + } } /** diff --git a/src/lib/Cookiebot_Deactivated.php b/src/lib/Cookiebot_Deactivated.php index 7a578c4c..56e10aae 100644 --- a/src/lib/Cookiebot_Deactivated.php +++ b/src/lib/Cookiebot_Deactivated.php @@ -13,7 +13,6 @@ class Cookiebot_Deactivated { */ public function run() { $this->run_addons_deactivation_hooks(); - $this->disable_banner(); } /** diff --git a/src/lib/Cookiebot_WP.php b/src/lib/Cookiebot_WP.php index 32e39182..838fe324 100644 --- a/src/lib/Cookiebot_WP.php +++ b/src/lib/Cookiebot_WP.php @@ -27,7 +27,7 @@ public static function debug_log( $message ) { } } - const COOKIEBOT_PLUGIN_VERSION = '4.6.2'; + const COOKIEBOT_PLUGIN_VERSION = '4.6.3'; const COOKIEBOT_MIN_PHP_VERSION = '5.6.0'; /** diff --git a/src/lib/script_loader_tag/Script_Loader_Tag.php b/src/lib/script_loader_tag/Script_Loader_Tag.php index 876f9b73..4964c65b 100644 --- a/src/lib/script_loader_tag/Script_Loader_Tag.php +++ b/src/lib/script_loader_tag/Script_Loader_Tag.php @@ -101,13 +101,24 @@ function ( $tag ) use ( $handle ) { } /** - * Modifies script tags to add the consent ignore attribute. + * Modifies script tags to add the consent attributes for WordPress 5.7+. + * Handles both consent-required scripts (from add_tag) and ignore scripts. * * @param array $attributes List of the attributes for the tag. * * @return array List of the attributes for the tag. */ public function cookiebot_add_consent_attribute_to_script_tag( $attributes ) { + // First, check if this script requires consent (registered via add_tag) + $handle = $this->extract_handle_from_attributes( $attributes ); + + if ( $handle && array_key_exists( $handle, $this->tags ) && ! empty( $this->tags[ $handle ] ) ) { + $attributes['type'] = 'text/plain'; + $attributes['data-cookieconsent'] = implode( ',', $this->tags[ $handle ] ); + return $attributes; + } + + // Then check if this script should be ignored (for admin scripts, etc.) if ( isset( $attributes['src'] ) && $this->check_ignore_script( $attributes['src'] ) ) { $attributes['data-cookieconsent'] = 'ignore'; } @@ -116,14 +127,29 @@ public function cookiebot_add_consent_attribute_to_script_tag( $attributes ) { } /** - * Modifies inline script tags to add the consent ignore attribute. + * Modifies inline script tags to add the consent attributes for WordPress 5.7+. + * Handles both consent-required inline scripts and ignored inline scripts. * * @param array $attributes List of the attributes for the tag. * * @return array List of the attributes for the tag. */ public function cookiebot_add_consent_attribute_to_inline_script_tag( $attributes ) { - if ( isset( $attributes['id'] ) && $this->is_inline_of_ignored_script( $attributes['id'] ) ) { + if ( ! isset( $attributes['id'] ) ) { + return $attributes; + } + + // Check if inline script belongs to a consent-required parent script + $base_handle = $this->extract_base_id_from_inline_id( $attributes['id'] ); + + if ( $base_handle && array_key_exists( $base_handle, $this->tags ) && ! empty( $this->tags[ $base_handle ] ) ) { + $attributes['type'] = 'text/plain'; + $attributes['data-cookieconsent'] = implode( ',', $this->tags[ $base_handle ] ); + return $attributes; + } + + // Check if inline script belongs to an ignored parent script + if ( $this->is_inline_of_ignored_script( $attributes['id'] ) ) { $attributes['data-cookieconsent'] = 'ignore'; } @@ -179,6 +205,30 @@ private function extract_base_id_from_inline_id( $inline_script_id ) { return preg_replace( '/-js-(extra|after|before)$/', '', $inline_script_id ); } + /** + * Extract the script handle from attributes array. + * WordPress typically sets the id attribute as "{handle}-js". + * + * @param array $attributes Script attributes. + * + * @return string|null Script handle or null if not found. + */ + private function extract_handle_from_attributes( $attributes ) { + if ( ! isset( $attributes['id'] ) ) { + return null; + } + + $id = $attributes['id']; + + // Remove the '-js' suffix that WordPress adds + if ( substr( $id, -3 ) === '-js' ) { + return substr( $id, 0, -3 ); + } + + // If no -js suffix, return the ID as-is (some scripts may not follow convention) + return $id; + } + /** * Check if the script tag attributes are valid for the injection of the consent ignore attribute. *