Skip to content

Fix disabled block allowlist handling - #228

Open
dknauss wants to merge 2 commits into
10up:developfrom
dknauss:pr/comment-blocks-preserve-disallow
Open

Fix disabled block allowlist handling#228
dknauss wants to merge 2 commits into
10up:developfrom
dknauss:pr/comment-blocks-preserve-disallow

Conversation

@dknauss

@dknauss dknauss commented Jul 5, 2026

Copy link
Copy Markdown

Description of the Change

Fixes an edge case in the disabled-comments block allowlist filter.

When another allowed_block_types_all filter has already returned false, WordPress interprets that as "no blocks allowed." The current comments filter replaces that value with a full registered-block allowlist minus comment blocks, which unintentionally re-enables blocks that an earlier filter disabled.

This change preserves false and only builds a filtered block list when blocks are otherwise allowed.

Benefits

  • Preserves WordPress/core filter semantics.
  • Avoids overriding stricter block restrictions from another plugin, theme, or project filter.
  • Keeps the existing comment-block removal behavior for normal true or array allowlists.

Possible Drawbacks

None expected. This only changes behavior when a previous filter has already disabled all blocks.

Verification Process

  • php -l includes/classes/Comments/Comments.php
  • composer run lint
  • git diff --check

Changelog Entry

Fixed - Preserve disabled block allowlists when removing comment blocks.

Checklist:

  • My code follows the code style of this project.
  • All new and existing tests pass. (No automated test suite exists in this repo; CI runs lint only.)

A note on tests

This change has unit-testable logic, but the plugin currently ships no test harness (no PHPUnit or e2e setup; CI runs lint only), so there's nothing here to add coverage to. I'm happy to contribute a minimal test setup plus coverage for this in a separate PR if that's welcome.

AI assistance was used in drafting and reviewing this change; final authorship and verification are mine.

@dknauss
dknauss force-pushed the pr/comment-blocks-preserve-disallow branch from e9dbda1 to 3a7bcb1 Compare July 5, 2026 02:44
@dknauss
dknauss force-pushed the pr/comment-blocks-preserve-disallow branch from 3a7bcb1 to 550e2f8 Compare July 5, 2026 02:59
@dknauss
dknauss marked this pull request as ready for review July 5, 2026 03:14
@jeffpaul
jeffpaul requested a lite review from Copilot August 12, 2026 15:22
@jeffpaul jeffpaul added this to the 1.20.0 milestone Aug 12, 2026

Copilot AI 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.

Pull request overview

This PR adjusts the allowed_block_types_all filter callback used by the comments-disabling feature to preserve WordPress’s “no blocks allowed” semantics when earlier filters disable blocks, instead of rebuilding an allowlist and accidentally re-enabling blocks.

Changes:

  • Updates the PHPDoc for remove_comment_blocks() to reflect boolean/array semantics.
  • Preserves upstream false values by returning false early.
  • Only builds an allowlist from the registry when blocks are otherwise allowed (e.g., true / unset list cases).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/classes/Comments/Comments.php
The expansion guard treated empty( $allowed_block_types ) as 'no list
set' and expanded it to every registered block. But an explicit empty
array is a deliberate deny-all — WordPress treats [] the same as false —
so an earlier filter disabling all blocks was silently overridden and
every block re-allowed. Drop the empty() clause: [] is an array and not
true, so it now flows through the filter loop unchanged (returns []).
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.

3 participants