Home / Docs / Hooks & WP-CLI

Developers: JavaScript API, hooks and WP-CLI

Everything you need to make your own code respect consent.

JavaScript API

ClearCrumb.get();              // the saved choice, or null
ClearCrumb.has( 'statistics' ); // true once the visitor allowed that category
ClearCrumb.open();             // open the preferences dialog
ClearCrumb.show();             // show the banner again

document.addEventListener( 'clearcrumb:consent', function ( e ) {
	if ( ClearCrumb.has( 'marketing' ) ) {
		// load your marketing code
	}
} );

Categories: necessary, preferences, statistics, marketing.

Block your own script

<script type="text/plain" data-cc-category="statistics" src="/my-stats.js"></script>

ClearCrumb releases it when the visitor allows statistics.

The consent cookie

The choice is stored in the first-party cookie clearcrumb_consent, for example 1.3.1760104931.9f3c…e21a.110: format version, banner revision, time, consent ID and one bit per optional category.

Shortcodes and blocks

  • [clearcrumb_preferences] — a link that opens the preferences.
  • [clearcrumb_cookie_policy] — the self-updating cookie policy.
  • Blocks: Cookie policy and Cookie settings link.

PHP filters

Filter Use
clearcrumb_block_page Return false to skip blocking on a request.
clearcrumb_log_days Days the consent log keeps records.
clearcrumb_region Change the region decided for a visitor.
clearcrumb_cookie_domain Share the consent cookie with a parent domain.
clearcrumb_layouts Register banner layouts.

ClearCrumb also supports the WP Consent API: wp_has_consent( 'statistics' ) works in your PHP and JavaScript.

WP-CLI

wp clearcrumb scan [--pages=<n>] [--format=table|json]
wp clearcrumb log export [--days=<n>] [--format=csv|json]