Skip to content

Add extension hooks for advanced (per-category) cookie consent - #256

Merged
davidperezgar merged 7 commits into
trunkfrom
feature/advanced-cookie-hooks
Aug 24, 2026
Merged

Add extension hooks for advanced (per-category) cookie consent#256
davidperezgar merged 7 commits into
trunkfrom
feature/advanced-cookie-hooks

Conversation

@davidperezgar

@davidperezgar davidperezgar commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds action/filter hooks to the Cookie Notice banner so an add-on can extend it without forking it:
    • frbl_cookie_notice_before_actions( $options ) — fires inside the actions row, before Reject/Accept.
    • frbl_cookie_notice_after_banner( $options ) — fires right after the banner markup, inside the same wp_footer output.
    • frbl_cookie_notice_default_accept_label / frbl_cookie_notice_default_reject_label — filters for the fallback button copy.
    • frbl_cookie_notice_consent_mode_state( $state, $consent ) — filter to override the four Consent Mode signals per category instead of a single binary decision.
  • Adds a [data-frbl-cookie-action="customize"] handler in the frontend JS (dispatches a frblCookieNoticeCustomize event, doesn't decide/hide the banner) and a window.frblCookieNoticeIsConsentStale() extension point so an add-on can force the banner to re-show when its own consent record goes stale.
  • Adds settings fields (Advanced Cookie Management toggle, Customize button label, Google Ads / Meta Pixel / Microsoft Clarity IDs) to the Cookie Notice settings section, gated behind the existing PRO-toggle pattern.
  • Bumps FRBL_VERSION to 1.6.0 and updates docs/COOKIE-NOTICE.md / readme.txt.

These hooks are consumed by FrontBlocks PRO's new Advanced Cookie Management module (see closemarketing/frontblocks-pro#54 and the companion PR on that repo) to add per-category consent (Necessary/Analytics/Marketing) on top of this banner. Nothing here changes the existing binary accept/reject behavior when the add-on isn't active — the new fields/hooks are all additive and no-ops if unused.

Test plan

  • composer lint clean on the touched files (JS/PHP syntax-checked with php -l / node --check; full phpcs/phpstan could not be run in this environment — composer install timed out fetching dev dependencies).
  • Manually verify the Cookie Notice banner (bar/box/popup layouts) still works with only this plugin active (no PRO): Accept/Reject behave exactly as before.
  • With FrontBlocks PRO's Advanced Cookie Management enabled, verify the "Customize" button appears and opens the categories dialog.

Generated by Claude Code

Open WordPress Playground Preview

Adds action/filter hooks to the Cookie Notice banner (before the
Reject/Accept buttons, after the banner markup, the Consent Mode default
signals, and the default button labels), plus a "Customize" action and a
staleness check in the frontend JS, and settings fields for the advanced
cookie categories feature. These are consumed by FrontBlocks PRO's new
Advanced Cookie Management module to add per-category consent without
forking this plugin's banner.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d715cdb4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread assets/cookie-notice/frontblocks-cookie-notice.js
Comment thread includes/Admin/Settings.php Outdated
Comment thread includes/Admin/Settings.php Outdated
- Remove the Advanced Cookie Management checkbox and integration ID
  fields from this plugin's Settings page — they now live entirely in
  FrontBlocks PRO's own settings (registered into this same section via
  the frontblocks_register_settings hook). This plugin now only shows a
  short upsell message pointing at that PRO feature.
- Fix CI lint failures introduced by the removed fields (now moot).
- Gate the wp_head bootstrap script and the JS fallback's tracking fetch
  by the same staleness check already used to keep the banner visible,
  so a per-category consent add-on invalidating old consent also stops
  tracking from starting on stale data, not just the banner from hiding.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e4d6c1d10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread includes/Frontend/CookieNotice.php Outdated
render_consent_mode_default() read the visitor's cookie server-side and
baked the resulting granted/denied values directly into the printed
<script>, breaking the cache-safety this module otherwise guarantees:
a full-page cache could serve one visitor's Consent Mode state to
another. Move the cookie read (and, for an add-on, the per-category
override) entirely client-side, mirroring the pattern already used by
render_consent_bootstrap_script() — only the fixed cookie name is
embedded server-side now, so the printed HTML is identical for every
visitor of a URL again.

Replaces the frbl_cookie_notice_consent_mode_state PHP filter (which had
the same problem by construction — any per-visitor value it returned
would get cached the same way) with a client-side override point,
window.frblCookieNoticeConsentModeState().

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04d31ea700

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread includes/Frontend/CookieNotice.php Outdated
Comment thread readme.txt Outdated
render_consent_mode_default()'s client-side cookie read didn't guard
decodeURIComponent() against malformed percent-encoding — a thrown
error there would abort before gtag('consent', 'default', ...) ever
ran, leaving independently loaded Google tags with no denied default.
Catch it the same way the bootstrap script below already does.

Also corrects the 1.6.0 changelog entry, which still named the removed
frbl_cookie_notice_consent_mode_state PHP filter instead of the
client-side window.frblCookieNoticeConsentModeState() override that
replaced it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17ba473c65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread includes/Frontend/CookieNotice.php
claude and others added 3 commits August 23, 2026 13:34
render_consent_mode_default() fell back to this plugin's own (possibly
still 'accepted') binary cookie whenever an add-on's per-category
override returned null for staleness — meaning an independently loaded,
Consent Mode-aware tag (e.g. Site Kit) could still get 'granted' before
the visitor answers a re-shown banner, even though the GTM/GA4 fetch
paths already correctly deny in that same situation. Reuse the existing
window.frblCookieNoticeIsConsentStale() check here too and force denied
when it reports stale, regardless of what the binary cookie says.
.frbl-cookie-notice__actions had flex-shrink: 0 but no flex-wrap, so once
a third button (e.g. PRO's "Customize", added via the new
frbl_cookie_notice_before_actions hook) joins Reject/Accept in the same
row, the three no longer fit — especially in the popup layout's 420px
panel — and the row overflows horizontally instead of wrapping, clipping
button text and forcing a horizontal scrollbar inside the panel.
@davidperezgar
davidperezgar merged commit 629ca50 into trunk Aug 24, 2026
6 checks passed
@davidperezgar
davidperezgar deleted the feature/advanced-cookie-hooks branch August 24, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants