From dc07b2d0d2ab3422e2369d3b52d5b62e335c77b5 Mon Sep 17 00:00:00 2001 From: Jasper Frumau Date: Sat, 30 May 2026 10:44:44 +0700 Subject: [PATCH 1/4] Block analytics scripts before consent; move sbjs_* to analytics category MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add script_loader_tag filter to block sourcebuster-js, wc-order-attribution, and wp_slimstat until analytics consent is given (type=text/plain + data-category attribute; vanilla-cookieconsent re-enables on accept) - Move sbjs_* autoClear from necessary to analytics — these are WooCommerce traffic-source tracking cookies, not essential cookies; placing them in necessary meant they could never be cleared on rejection - Expose warder_blocked_scripts filter for site-specific overrides --- inc/defaults.php | 11 +++++----- inc/frontend.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/inc/defaults.php b/inc/defaults.php index c321b20..029f163 100644 --- a/inc/defaults.php +++ b/inc/defaults.php @@ -33,12 +33,7 @@ function warder_get_default_options() { 'description' => 'These cookies are essential for the proper functioning of the website and cannot be disabled.', 'enabled' => true, 'readonly' => true, - 'cookies' => array( - array( - 'name' => '/^sbjs_/', - 'is_regex' => true, - ), - ), + 'cookies' => array(), ), 'analytics' => array( 'title' => 'Performance and Analytics', @@ -66,6 +61,10 @@ function warder_get_default_options() { 'name' => '/^mtm_/', 'is_regex' => true, ), + array( + 'name' => '/^sbjs_/', + 'is_regex' => true, + ), ), ), ), diff --git a/inc/frontend.php b/inc/frontend.php index 07da73c..a46fd82 100644 --- a/inc/frontend.php +++ b/inc/frontend.php @@ -112,3 +112,60 @@ function warder_add_preferences_button() { echo ''; } add_action( 'wp_footer', 'warder_add_preferences_button' ); + +/** + * Blocks known analytics/marketing scripts until the matching consent category + * is accepted by rewriting their type to "text/plain" and adding data-category. + * + * vanilla-cookieconsent holds type="text/plain" scripts and re-executes them + * (as type="text/javascript") once the user accepts the named category. This + * prevents scripts like WooCommerce's SourceBuster (which sets sbjs_* cookies) + * and Slimstat from firing before consent. + * + * Site owners can extend or override the list via the warder_blocked_scripts filter. + * + * @param string $tag The full