Skip to content

Commit 76c71cf

Browse files
committed
Editor: Hide Classic Block from inserter
1 parent bd4e3c9 commit 76c71cf

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/wp-includes/default-filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@
627627
add_action( 'enqueue_block_editor_assets', 'wp_enqueue_block_editor_script_modules' );
628628
add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' );
629629
add_action( 'enqueue_block_editor_assets', '_wp_enqueue_auto_register_blocks' );
630+
add_action( 'enqueue_block_editor_assets', 'wp_declare_classic_block_necessary' );
630631
add_action( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
631632
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
632633
add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 );

src/wp-includes/script-loader.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,33 @@ function wp_enqueue_global_styles() {
26472647
wp_add_global_styles_for_blocks();
26482648
}
26492649

2650+
/**
2651+
* Declares a flag that the Classic block is necessary for the current post.
2652+
*
2653+
* @since 7.1.0
2654+
*/
2655+
function wp_declare_classic_block_necessary() {
2656+
global $post;
2657+
2658+
/**
2659+
* Filters whether the Classic block should be available in the inserter.
2660+
*
2661+
* Defaults to false. Use this filter to opt in (globally or per post).
2662+
*
2663+
* @param bool $supports_inserter Whether the Classic block is available in the inserter.
2664+
* @param WP_Post|null $post The post being edited, or null if not in the post editor.
2665+
*/
2666+
if ( ! (bool) apply_filters( 'wp_classic_block_supports_inserter', false, $post ) ) {
2667+
return;
2668+
}
2669+
2670+
wp_add_inline_script(
2671+
'wp-block-library',
2672+
'window.__needsClassicBlock = true;',
2673+
'before'
2674+
);
2675+
}
2676+
26502677
/**
26512678
* Checks if the editor scripts and styles for all registered block types
26522679
* should be enqueued on the current screen.

0 commit comments

Comments
 (0)