-
Notifications
You must be signed in to change notification settings - Fork 32
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 PHP 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.