Hooks

|

Indhold

Bemærk:
Dette indhold er desværre ikke tilgængeligt på dit sprog i øjeblikket. Lige nu kan du kun læse det på engelsk. Tak for din forståelse!

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

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

/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;
}, 10, 2);

/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;
}, 10, 3);

/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;
}, 10, 3);

/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',]);
});

/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;
});

/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);

/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;
});

/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;
}, 10, 2);

/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

/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;
});

/modifyLanguageCode

Change the $languageCode before validating given consents.

Example:

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

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;
});

/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;
}, 10, 2);

Script Blocker

/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;
});

/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;
});

/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;
});

/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;
});

/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;
}, 10, 2);

Script Builder

/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;
});

/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);

/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;
});

/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;
});

/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;
});

/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;
});

/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;
});

/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;
});

/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;
});

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;
});

/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;
}, 10, 2);

/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

/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;
});

/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;
}, 10, 2);

Style Blocker

/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;
});

/shouldBlockUrl

Allows you to block a <link> tag whose rel attribute has one of the following values: dns-prefetchmodulepreloadpreconnectprefetch, or preload.

Example:

add_filter('borlabsCookie/styleBlocker/shouldBlockUrl', function (?bool $status = null, ?array $attributes = null, ?string $url = null): ?bool {
    if ($status) {
        return $status;
    }

    /*
     * Check a condition and return `true` to block the URL,
     * otherwise return $status unchanged.
     */

    return $status;
}, 10, 3);

/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;
});

/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;
}, 10, 2);

Style Builder

/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;
});

Third-Party Cache Clearer

/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

/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;
});

/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;
});

/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;
});

/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;
});

/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;
});

Var denne artikel nyttig?

Nyttig
Ikke nyttig

Kunne du ikke finde det, du ledte efter? Vores supportteam er klar til at hjælpe.