Skip to content

bug in Script_Loader_Tag init #340

Open

Description

@Kevin-Hamilton

Script Loader Tag bug

See:

} 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

  1. Kevin-Hamilton commented on Apr 11, 2025

    @Kevin-Hamilton
    Author

    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.

  2. Kevin-Hamilton commented on Jun 16, 2025

    @Kevin-Hamilton
    Author

    @apinto-uc @lucantoniouc any comment on this? Is it a bug or am I mistaken?

  3. apinto-uc commented on Jul 1, 2025

    @apinto-uc
    Collaborator

    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

  4. codepuncher commented on Dec 10, 2025

    @codepuncher

    I have to say, I'm fairly confused on how this bug has not surfaced sooner.

    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.

  5. Kevin-Hamilton commented on Jan 18, 2026

    @Kevin-Hamilton
    Author

    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?

  6. lucantoniouc commented on Jan 19, 2026

    @lucantoniouc
    Collaborator

    Hey @Kevin-Hamilton this issue was addressed by @hnikoloski-uc the fix is on its way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions