Hooks

Table Of Contents

In the examples, add_filter is used, but if you are using Compatibility Patches, you MUST use the addFilter() method of the WpFunction class.

Compatibility Patch

borlabsCookie/compatibilityPatch/beforeFileDeletion/{key}

The filter provides the capability to perform an extra routine during the uninstallation process. It can be utilized to remove files generated by the Compatibility Patch. Please note that the filter MUST only be associated with a single callback function, and multiple callbacks are not allowed.

Example:

add_filter('borlabsCookie/compatibilityPatch/beforeFileDeletion/my-key', function (CompatibilityPatchModel $compatibilityPatchModel) {
    // For example: Delete files created by the compatibility patch
});

Content Blocker

borlabsCookie/contentBlocker/blocking/afterBlocking/{key}

Modify the content after the blocking process has been completed.

Example:

add_filter('borlabsCookie/contentBlocker/blocking/afterBlocking/my-key', function (string $content, array $atts) {
    // Modify $content, e.g. $content .= '<div>was modified</div>';
    return $content;
});

borlabsCookie/contentBlocker/blocking/afterDetermination/{key}

Modify the model before it blocks the content on the website.

Example:

add_filter('borlabsCookie/contentBlocker/blocking/afterDetermination/my-key', function (ContentBlockerModel $model, array $atts, string $content) {
    // Modify $model, e.g. $model->previewHtml .= 'was modified';
    return $model;
});

borlabsCookie/contentBlocker/blocking/beforeBlocking/{key}

Modify the content to be blocked on the website.

Example:

add_filter('borlabsCookie/contentBlocker/blocking/beforeBlocking/my-key', function (string $content, array $atts, ContentBlockerModel $model) {
    // Modify $content, e.g. $content .= '<div>was modified</div>';
    return $content;
});

borlabsCookie/contentBlocker/modifyExcludedHostnames

Allows you to add or remove hostnames to the list of hostnames whose content should not be blocked.

Example:

add_filter('borlabsCookie/contentBlocker/modifyExcludedHostnames', function (array $hostnames) {
    return array_merge($hostnames, ['.hostname-a.internal', 'hostname-b.internal',]);
});

borlabsCookie/contentBlocker/modifyPostDataBeforeSaving

Change the $postData before the model object is created and added/updated to the table.

Example:

add_filter('borlabsCookie/contentBlocker/modifyPostDataBeforeSaving', function (array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        // Modify $postData
	}
    return $postData;
});

borlabsCookie/contentBlocker/skipIframeBlocking

Allows to skip blocking of an iframe.

Example:

add_filter(
    'borlabsCookie/contentBlocker/skipIframeBlocking',
    /**
     * @var array{iframeTag: string, srcIframe: array} $attributes
     */
    function (bool $status, array $attributes) {
        if ($status) {
            return $status;
        }
    
        /*
         * Check a condition and return `true` to skip blocking,
         * otherwise return $status with no change.
         */
    
        return $status;
    },
    10,
    2
);

borlabsCookie/contentBlocker/skipInitialization

Allows to disable initialization to prevent content from being blocked.

Example:

add_filter('borlabsCookie/contentBlocker/skipInitialization', function (?bool $status = null) {
    if ($status) {
        return $status;
    }
    /*
     * Check a condition and return `true` to skip initialization, 
     * otherwise return $status with no change.
     */
    return $status;
});

borlabsCookie/contentBlocker/validate

Add additional validations of $postData before saving.

Example:

add_filter('borlabsCookie/contentBlocker/validate', function (Validator $validator, array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        $validator->isNotEmptyString(
            'My Custom Field,
            $postData['my-custom-field'],
        );
	}
    return $validator;
});

borlabsCookie/contentBlocker/view/edit/modifyTemplateData

Change the $templateData before passing it to the template.

Example:

add_filter('borlabsCookie/contentBlocker/view/edit/modifyTemplateData', function (array $templateData) {
    if ($templateData['data']['key'] ?? null === 'my-key') {
        $templateData['data']['settingsFields']->list[0]->value = 0;
	}
    return $templateData;
});

Cross Domain Cookie

borlabsCookie/crossDomainCookie/modifyConsents

Change the $consents before validation. This can be useful if, for example, you have named a service group or service differently on the target system.

Example:

add_filter('borlabsCookie/crossDomainCookie/modifyConsents', function (array $consents) {
    /**
    * @var $consents Modify consents
    * Example:
    * <code>
    *  [
    *      "essential": ["borlabs-cookie"],
    *  ]
    * </code>
    */
	$consents['preferences'] = $consents['external-media'];
	unset($consents['external-media']);
    return $consents;
});

borlabsCookie/crossDomainCookie/modifyLanguageCode

Change the $languageCode before validating given consents.

Example:

add_filter('borlabsCookie/crossDomainCookie/modifyLanguageCode', function (string $languageCode, array $requestDto) {
    // Modify $languageCode
    return $languageCode;
});

Provider

borlabsCookie/provider/modifyPostDataBeforeSaving

Change the $postData before the model object is created and added/updated to the table.

Example:

add_filter('borlabsCookie/provider/modifyPostDataBeforeSaving', function (array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        // Modify $postData
	}
    return $postData;
});

borlabsCookie/provider/validate

Add additional validations of $postData before saving.

Example:

add_filter('borlabsCookie/provider/validate', function (Validator $validator, array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        $validator->isNotEmptyString(
            'My Custom Field,
            $postData['my-custom-field'],
        );
	}
    return $validator;
});

Script Blocker

borlabsCookie/scriptBlocker/blocking/afterBlocking/{key}

Modify the script tag after it was modified by the script blocker.

Example:

add_filter('borlabsCookie/scriptBlocker/blocking/afterBlocking/my-key', function (string $scriptTag) {
    // Modify $scriptTag, e.g. $scriptTag .= '<div>Add an element below the blocked script.</div>';
    return $scriptTag;
});

borlabsCookie/scriptBlocker/blocking/modifyScriptTagContent/{key}

Modify the content of the script tag. When the onExist setting is applied, the content of the script tag contains the already modified code from Borlabs Cookie.

Example:

add_filter('borlabsCookie/scriptBlocker/blocking/modifyScriptTagContent/my-key', function (string $scriptTagContent) {
    // Modify $scriptTagContent, e.g. $scriptTagContent = str_replace('DOMContentLoaded', 'myAlternativeEvent', $scriptTagContent);
    return $scriptTagContent;
});

borlabsCookie/scriptBlocker/modifyPostDataBeforeSaving

Change the $postData before the model object is created and added/updated to the table.

Example:

add_filter('borlabsCookie/scriptBlocker/modifyPostDataBeforeSaving', function (array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        // Modify $postData
	}
    return $postData;
});

borlabsCookie/scriptBlocker/skipInitialization

Allows to disable initialization to prevent scripts from being blocked.

Example:

add_filter('borlabsCookie/scriptBlocker/skipInitialization', function (?bool $status = null) {
    if ($status) {
        return $status;
    }
    /*
     * Check a condition and return `true` to skip initialization, 
     * otherwise return $status with no change.
     */
    return $status;
});

borlabsCookie/scriptBlocker/validate

Add additional validations of $postData before saving.

Example:

add_filter('borlabsCookie/scriptBlocker/validate', function (Validator $validator, array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        $validator->isNotEmptyString(
            'My Custom Field,
            $postData['my-custom-field'],
        );
	}
    return $validator;
});

Service

borlabsCookie/service/modifyPostDataBeforeSaving

Change the $postData before the model object is created and added/updated to the table.

Example:

add_filter('borlabsCookie/service/modifyPostDataBeforeSaving', function (array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        // Modify $postData
	}
    return $postData;
});

borlabsCookie/service/validate

Add additional validations of $postData before saving.

Example:

add_filter('borlabsCookie/service/validate', function (Validator $validator, array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        $validator->isNotEmptyString(
            'My Custom Field,
            $postData['my-custom-field'],
        );
	}
    return $validator;
});

borlabsCookie/service/view/edit/modifyTemplateData

Change the $templateData before passing it to the template.

Example:

add_filter('borlabsCookie/service/view/edit/modifyTemplateData', function (array $templateData) {
    if ($templateData['data']['key'] ?? null === 'my-key') {
        $templateData['data']['settingsFields']->list[0]->value = 0;
	}
    return $templateData;
});

Service Group

borlabsCookie/serviceGroup/modifyPostDataBeforeSaving

Change the $postData before the model object is created and added/updated to the table.

Example:

add_filter('borlabsCookie/serviceGroup/modifyPostDataBeforeSaving', function (array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        // Modify $postData
	}
    return $postData;
});

borlabsCookie/serviceGroup/validate

Add additional validations of $postData before saving.

Example:

add_filter('borlabsCookie/serviceGroup/validate', function (Validator $validator, array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        $validator->isNotEmptyString(
            'My Custom Field,
            $postData['my-custom-field'],
        );
	}
    return $validator;
});

Style Blocker

borlabsCookie/styleBlocker/modifyPostDataBeforeSaving

Change the $postData before the model object is created and added/updated to the table.

Example:

add_filter('borlabsCookie/styleBlocker/modifyPostDataBeforeSaving', function (array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        // Modify $postData
	}
    return $postData;
});

borlabsCookie/styleBlocker/skipInitialization

Allows to disable initialization to prevent styles from being blocked.

Example:

add_filter('borlabsCookie/styleBlocker/skipInitialization', function (?bool $status = null) {
    if ($status) {
        return $status;
    }
    /*
     * Check a condition and return `true` to skip initialization, 
     * otherwise return $status with no change.
     */
    return $status;
});

borlabsCookie/styleBlocker/validate

Add additional validations of $postData before saving.

Example:

add_filter('borlabsCookie/styleBlocker/validate', function (Validator $validator, array $postData) {
    if ($postData['key'] ?? null === 'my-key') {
        $validator->isNotEmptyString(
            'My Custom Field,
            $postData['my-custom-field'],
        );
	}
    return $validator;
});

Third-Party Cache Clearer

borlabsCookie/thirdPartyCacheClearer/shouldClearCache

Allows to override the clearThirdPartyCache setting and also provides the ability to run a custom cache clearing routine.

Example:

add_filter('borlabsCookie/thirdPartyCacheClearer/shouldClearCache', function (bool $shouldClearCache) {
    // Modify $shouldClearCache or execute your own routine to clear the cache
    return $shouldClearCache;
});

WordPress Frontend

borlabsCookie/frontendResources/disableCssLoading

The filter allows you to disable the loading of CSS resources from Borlabs Cookie in the frontend.

Example:

add_filter('borlabsCookie/frontendResources/disableCssLoading', function (bool $status = false) {
    // $status = true;
    return $status;
});

borlabsCookie/frontendResources/disableDebugConsole

The filter allows you to disable the loading of the Borlabs Cookie Debug Console in the frontend.

Example:

add_filter('borlabsCookie/frontendResources/disableDebugConsole', function (bool $status = false) {
    // $status = true;
    return $status;
});

borlabsCookie/frontendResources/disableJavaScriptLoading

The filter allows you to disable the loading of JavaScript resources from Borlabs Cookie in the frontend.

Example:

add_filter('borlabsCookie/frontendResources/disableJavaScriptLoading', function (bool $status = false) {
    // $status = true;
    return $status;
});

borlabsCookie/frontendResources/disabledOnRestRequest

By default, all resources (CSS and JavaScript files) are not queued for a REST request. The filter allows you to enable the resources for a REST request.

Example:

add_filter('borlabsCookie/frontendResources/disabledOnRestRequest', function (bool $status = true) {
    // $status = false;
    return $status;
});

borlabsCookie/outputBufferManager/status

Allows to disable buffering, e.g. when a page builder is active.

Example:

add_filter('borlabsCookie/outputBufferManager/status', function (bool $status = true) {
    // $status = false;
    return $status;
});

borlabsCookie/scriptBuilder/iabTcf/modifyHostnamesForConsentAddition

Allows you to add or remove hostnames from the list. This list determines which <a> tags on your website gets the consent string added to their query strings.

Example:

add_filter('borlabsCookie/scriptBuilder/iabTcf/modifyHostnamesForConsentAddition', function (array $hostnames) {
    // Modify $hostnames
	$hostnames[] = 'example.local';
	
    return $hostnames;
});

borlabsCookie/scriptBuilder/modifyConfigBeforeSaving

Allows you to modify the configuration before the config file is generated.

Example:

add_filter('borlabsCookie/scriptBuilder/modifyConfigBeforeSaving', function (array $config, array $attributes) {
	// The language associated with `$config` is stored in `$attributes['languageCode']`.
    return $config;
}, 10, 2);

borlabsCookie/scriptBuilder/service/modifyFallbackCode/

Modify the fallback code before it is inserted into the website head. This filter is applied before the corresponding filter is executed for a specific service.

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyFallbackCode/', function (string $fallbackCode) {
    // Modify $fallbackCode
    return $fallbackCode;
});

borlabsCookie/scriptBuilder/service/modifyFallbackCode/{key}

Modify the fallback code before it is inserted into the website head.

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyFallbackCode/my-key', function (string $fallbackCode) {
    // Modify $fallbackCode
    return $fallbackCode;
});

borlabsCookie/scriptBuilder/service/modifyPlaceholders/{key}

Allows you to add placeholders to $searchAndReplace['search'] which will subsequently be substituted with values from $searchAndReplace['replace'].

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyPlaceholders/my-key', function (array $searchAndReplace) {
    // Modify $searchAndReplace
	// $searchAndReplace['search'][] = '{{ myTrackingIdPlaceholder }}';
	// $searchAndReplace['replace'][] = 'let someTrackingId = \'ID-12345678\';';
    return $searchAndReplace;
});

borlabsCookie/scriptBuilder/service/modifyOptInCode/

Modify the opt-in code before it is written to the JavaScript config file. This filter is applied before the corresponding filter is executed for a specific service.

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyOptInCode/', function (string $optInCode) {
    // Modify $optInCode
    return $optInCode;
});

borlabsCookie/scriptBuilder/service/modifyOptInCode/{key}

Modify the opt-in code before it is written to the JavaScript config file.

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyOptInCode/my-key', function (string $optInCode) {
    // Modify $optInCode
    return $optInCode;
});

borlabsCookie/scriptBuilder/service/modifyOptOutCode/

Modify the opt-out code before it is written to the JavaScript config file. This filter is applied before the corresponding filter is executed for a specific service.

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyOptOutCode/', function (string $optOutCode) {
    // Modify $optOutCode
    return $optOutCode;
});

borlabsCookie/scriptBuilder/service/modifyOptOutCode/{key}

Modify the opt-out code before it is written to the JavaScript config file.

Example:

add_filter('borlabsCookie/scriptBuilder/service/modifyOptOutCode/my-key', function (string $optOutCode) {
    // Modify $optOutCode
    return $optOutCode;
});

borlabsCookie/styleBuilder/modifyCss

The filter allows you to modify or extend CSS from the frontend of Borlabs Cookie.

Example:

add_filter('borlabsCookie/styleBuilder/modifyCss', function (string $css) {
    // Modify or extend $css
	$css .= '.myContainer { background: red; }';
    return $css;
});

What are your feelings

Updated on Januar 6, 2026