Skip to content

Disable Classic block: Control inserter support via filter#77845

Merged
yuliyan merged 3 commits intoWordPress:trunkfrom
yuliyan:update/classic-block-experiment-inserter-conditions
May 1, 2026
Merged

Disable Classic block: Control inserter support via filter#77845
yuliyan merged 3 commits intoWordPress:trunkfrom
yuliyan:update/classic-block-experiment-inserter-conditions

Conversation

@yuliyan
Copy link
Copy Markdown
Contributor

@yuliyan yuliyan commented Apr 30, 2026

What?

Add a gutenberg_classic_block_supports_inserter filter to control whether the Classic block is available in the inserter. Defaults to false.

The previous post-content check is no longer necessary. Since we switched to registering the Classic block unconditionally in #77840, existing posts that use the Classic block will continue to work - we just don't allow new instances to be inserted.

Why?

Previously, the Classic block was made available in the inserter when the post being edited already contained one. For the experiment, we want a stricter default - hide the Classic block from the inserter, and let developers opt in explicitly.

How?

The Classic block's inserter visibility is now driven by a single PHP filter. The result is exposed to JS through the existing window.wp.needsClassicBlock flag, which the block reads via supports.inserter. The filter receives the post being edited (or null) so callbacks can decide based on context.

Testing Instructions

  1. Open a post in the block editor with the "Disable Classic block" experiment enabled.
  2. Confirm the Classic block is not in the inserter, even on posts that already contain a Classic block.
  3. Add this snippet to a plugin or mu-plugins:
add_filter( 'gutenberg_classic_block_supports_inserter', '__return_true' );

Testing Instructions for Keyboard

Screenshots or screencast

N/A

Use of AI Tools

Cursor with Opus 4.7

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Apr 30, 2026
@yuliyan yuliyan requested a review from tyxla April 30, 2026 14:07
@yuliyan yuliyan added the [Type] Experimental Experimental feature or API. label Apr 30, 2026
@yuliyan yuliyan force-pushed the update/classic-block-experiment-inserter-conditions branch from 775b52e to 710c62f Compare May 1, 2026 08:04
@yuliyan yuliyan force-pushed the update/classic-block-experiment-inserter-conditions branch from 710c62f to 61aa520 Compare May 1, 2026 08:49
@github-actions github-actions Bot removed the [Package] Block library /packages/block-library label May 1, 2026
@yuliyan yuliyan added No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels May 1, 2026
@yuliyan yuliyan marked this pull request as ready for review May 1, 2026 08:51
@yuliyan yuliyan requested a review from spacedmonkey as a code owner May 1, 2026 08:51
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yuliyan <yuliyan@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment thread lib/client-assets.php
function gutenberg_register_block_library_script_special_case( $scripts ) {
$handle = 'wp-block-library';
$script = $scripts->query( $handle, 'registered' );
if (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The block is no longer registered conditionally, so this dependency doesn't need to be conditional either - editor is required whenever the Classic block can render, which is now always.

Copy link
Copy Markdown
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Confirming the filter works well, and the block is hidden from the inserter (including in block visibility settings) by default, while existing Classic block instances continue to work regardless.

🚢

@tyxla tyxla added the Needs Dev Note Requires a developer note for a major WordPress release cycle label May 1, 2026
@tyxla
Copy link
Copy Markdown
Member

tyxla commented May 1, 2026

I think this could use a dev note for the new filter, btw.

Especially considering that we're planning to remove the experimental wrapper before 7.1 ships.

@yuliyan
Copy link
Copy Markdown
Contributor Author

yuliyan commented May 1, 2026

Dev Note

Classic block: New filter to control inserter availability

The Classic block (core/freeform) no longer appears in the inserter by default. Whether it's available in the inserter is controlled by a new filter. Existing posts that contain a Classic block continue to render and can be edited as before.

New filter: gutenberg_classic_block_supports_inserter

/**
 * @param bool         $supports_inserter Whether the Classic block is available in the inserter.
 * @param WP_Post|null $post              The post being edited, or null if not in the post editor.
 */
apply_filters( 'gutenberg_classic_block_supports_inserter', false, $post );

The filter defaults to false, meaning the Classic block is hidden from the inserter by default. The result is exposed to JavaScript via the existing window.wp.needsClassicBlock flag, which the Classic block reads through its supports.inserter value.

Examples

Enable globally:

add_filter( 'gutenberg_classic_block_supports_inserter', '__return_true' );

Enable per post (e.g. only for pages):

add_filter(
	'gutenberg_classic_block_supports_inserter',
	function ( $supports, $post ) {
		return $supports || ( $post && 'page' === $post->post_type );
	},
	10,
	2
);

Enable for posts that already contain a Classic block (replicates the previous default behaviour):

add_filter(
	'gutenberg_classic_block_supports_inserter',
	function ( $supports, $post ) {
		if ( $supports || ! $post || empty( $post->post_content ) ) {
			return $supports;
		}

		foreach ( parse_blocks( $post->post_content ) as $block ) {
			$is_freeform = empty( $block['blockName'] ) || 'core/freeform' === $block['blockName'];

			if ( $is_freeform && '' !== trim( $block['innerHTML'] ) ) {
				return true;
			}
		}

		return $supports;
	},
	10,
	2
);

@yuliyan
Copy link
Copy Markdown
Contributor Author

yuliyan commented May 1, 2026

Posted a dev note for once the experiment wrapper is removed.

@yuliyan yuliyan added has dev note when dev note is done (for upcoming WordPress release) and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels May 1, 2026
@yuliyan yuliyan merged commit e1e460a into WordPress:trunk May 1, 2026
53 of 54 checks passed
@github-actions github-actions Bot added this to the Gutenberg 23.2 milestone May 1, 2026
@Mamaduka
Copy link
Copy Markdown
Member

Mamaduka commented May 1, 2026

Nice work!

Do we have a tracking issue related to this effort?

@tyxla
Copy link
Copy Markdown
Member

tyxla commented May 1, 2026

@Mamaduka, there's been a fair amount of work on it this week.

Thanks - a tracking issue makes sense - we'll add one next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has dev note when dev note is done (for upcoming WordPress release) No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants