Disable Comments: blocks registered only in JavaScript can't be inserted while the module is on

Open
#1,012 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
backend, devtools

Research direction

Read the allowed_block_types_all callback in obfx_modules/disable-comments/init.php (lines 159–194), then reproduce with the Playground link and the qa/js-only block registration from the issue. Check how the callback handles an incoming true value and PHP-registered blocks. Done when JavaScript-only blocks remain insertable with Disable Comments on while comment blocks stay unavailable.

Written by the indexing model from the issue text.

Description

Disable Comments: blocks registered only in JavaScript can't be inserted while the module is on

With Disable Comments on, the block editor no longer lets you insert any block that a plugin registers only in JavaScript (no PHP register_block_type()). Core blocks and PHP-registered blocks are unaffected. The comment blocks are removed as intended.

Seen on Orbit Fox 3.0.12 with WordPress 7.1.3 and 7.1.4.

Try it in Playground: WordPress latest (7.1.4), Neve, Orbit Fox with Disable Comments on; it opens a new post in the editor.

Checked through that link, with a test block registered from the console: canInsertBlockType('qa/js-only') is false, core/paragraph is true, core/comments is false (as intended). With the module off, the same test block is insertable.

Steps to reproduce
  1. Orbit Fox → General Settings: turn on Disable Comments.
  2. Open a new post in the block editor and open the browser console.
  3. Run:
    wp.blocks.registerBlockType('qa/js-only',{apiVersion:3,title:'QA JS only',category:'text',edit:()=>null,save:()=>null});
    wp.data.select('core/block-editor').canInsertBlockType('qa/js-only')
    
    (Or, without the console: use any plugin whose blocks are registered only in JavaScript, and search the inserter for one of them.)
  4. Turn Disable Comments off, reload the editor and run the same lines.

Expected: true in both cases, and the block is in the inserter.
Actual: false while Disable Comments is on; true once it's off.

Cause

obfx_modules/disable-comments/init.php, the allowed_block_types_all callback (lines 159–194): when the incoming value is true ("all blocks allowed"), it replaces it with the list of blocks registered in PHP (WP_Block_Type_Registry::get_instance()->get_all_registered(), lines 179–182) minus the comment blocks. Blocks registered only in JavaScript aren't in that registry, so they drop out of the allowed list.

Possible fix

Leave true alone and remove the comment blocks on the client instead (for example wp.blocks.unregisterBlockType() for each disallowed block in an editor script, or wp.hooks' blocks.registerBlockType filter). Only filter when the incoming value is already an array. Not tried; a suggestion from the code.

Found while building Orbit Fox's compatibility checks (Codeinwp/qa-compatibility#100), where it is recorded as a known difference: the same on every WordPress version tested.

Dominant language
PHP
Stars
13
Forks
18
Avg merge
1d 12h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Codeinwp/themeisle-companion

All issues in Codeinwp/themeisle-companion

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.