bug in Script_Loader_Tag init #340
Description
Script Loader Tag bug
See:
CookiebotWP/src/lib/script_loader_tag/Script_Loader_Tag.php
Lines 36 to 38 in 84dedab
| } else { | |
| add_filter( 'script_loader_tag', array( $this, 'cookiebot_add_consent_attribute_to_tag' ), 10, 3 ); | |
| } |
The cookiebot_add_consent_attribute_to_tag filter function is never called if WordPress is version 5.7.0 or greater. I believe this line should not be within an else clause.
Additional details and related info
This issue was also identified by another developer and mentioned 3 months ago here: https://wordpress.org/support/topic/woocommerce-sbjs-sourcebuster/#post-18230010
I found this issue while I was trying to solve a similar problem as @codepuncher, but in my case the CookieBot JS had already identified the sourcebuster.js as responsible for setting marketing cookies and was blocking it from loading but did not respect the fact that the order-attribution.js script depends sourcebuster.js, so I was getting console log errors from order-attribution which was trying to use an unintialized sbjs global. Even if I agreed to marketing cookies, order-attribution.js would load before sourcebuster.js.
My fix was to add this to my theme:
function element_customize_cookiebot_consent_tags() {
if(function_exists('\cybot\cookiebot\lib\cookiebot_active') && \cybot\cookiebot\lib\cookiebot_active()) {
$script_loader_tag = new \cybot\cookiebot\lib\script_loader_tag\Script_Loader_Tag();
$script_loader_tag->add_tag( 'wc-order-attribution', array('marketing') );
}
}
add_action( 'wp_loaded', 'element_customize_cookiebot_consent_tags', 10, 0 );If this is improper use of the script_loader_tag interface, let me know. It did seem a little bit concerning to me that there isn't a singleton instance of script_loader_tag that I could find. Having multiple instances of this class instantiated might not be ideal.
Activity
Kevin-Hamilton commentedon Apr 11, 2025
I have to say, I'm fairly confused on how this bug has not surfaced sooner.
The problematic if/else statement has been in place for 13 months now. There are about 30 instances of calls to
$this->script_loader_tag->add_tag()found within the cookiebot/src/addons folder. I don't think any of them are working properly.Kevin-Hamilton commentedon Jun 16, 2025
@apinto-uc @lucantoniouc any comment on this? Is it a bug or am I mistaken?
apinto-uc commentedon Jul 1, 2025
Hi Kevin,
Thank you for taking the time to report this issue. We've received your feedback and we will investigate the problem you've encountered.
We'll keep you updated on our progress and let you know once we have more information or a resolution.
Best regards,
Antonio Pinto
codepuncher commentedon Dec 10, 2025
I had the exact same thoughts myself @Kevin-Hamilton
@apinto-uc are there any updates on the issue? It's been quite a while now for such a large issue.
Let us know if we can help at all.
Kevin-Hamilton commentedon Jan 18, 2026
There have been 11 new releases of the plugin since this issue was reported, but no progress on this issue.
@apinto-uc , @fabianwgl would it be helpful for me to submit a pull request for this?
lucantoniouc commentedon Jan 19, 2026
Hey @Kevin-Hamilton this issue was addressed by @hnikoloski-uc the fix is on its way