Add vip_governance__deny_message filter for custom block-deny snackbar#137
Open
smithjw1 wants to merge 1 commit into
Open
Add vip_governance__deny_message filter for custom block-deny snackbar#137smithjw1 wants to merge 1 commit into
smithjw1 wants to merge 1 commit into
Conversation
…ackbar Replaces Gutenberg's generic "Block 'X' can't be inserted." snackbar with one that integrators can override via the new vip_governance__deny_message JS filter, giving editors meaningful context (e.g. who to contact) instead of a message that reads like a bug. Closes #136. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #136.
When a block is restricted by governance rules, Gutenberg's block inserter shows a generic "Block 'X' can't be inserted." snackbar that gives editors no context — non-technical users interpret it as a bug. This PR adds a JS filter,
vip_governance__deny_message, that integrators can use to replace that copy with something meaningful (e.g. who to contact).How it works
core/noticeswatches for Gutenberg'sinserter-noticesnackbar (dispatched in@wordpress/block-editor'suse-block-types-state.jswhen an inserter selection is denied).__()so it follows the active locale; supports both%sand numbered%1$splaceholders), resolves the matchingblockNamevia the blocks store, runs everything through the newvip_governance__deny_messagefilter, removes WP's snackbar, and dispatches our own.vip_governance__is_block_allowed_for_insertionfilter —(message, blockName, blockTitle, governanceRules).Docs
vip_governance__deny_messagesection added toREADME.md(Code Filters) with signature and an integrator example.AGENTS.md.Open question for the team
Should we also add a
denyMessagefield to the governance rules JSON schema (per-rule, alongsideallowedBlocks/blockSettings), so non-technical admins can configure the copy without writing JS? The filter shipped here lets integrators override programmatically; a schema field would complement it for the no-code case mentioned in the issue. Happy to do as a small follow-up PR if there's appetite.Steps to Test
npm install && npm run build.wp-env startand log in at http://localhost:8889 (admin/password).inserter-noticeis gone —wp.data.select('core/notices').getNotices()should not contain it).npm run test:js— 33 tests pass.wp-env start && npx playwright install chromium && npx playwright test --grep "deny-snackbar|vip_governance__deny_message"— both new E2E tests pass.🤖 Generated with Claude Code