From 76c71cf54f4ce3f102a1dbf078917b7eac813a58 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Tue, 5 May 2026 16:25:13 +0300 Subject: [PATCH 1/2] Editor: Hide Classic Block from inserter --- src/wp-includes/default-filters.php | 1 + src/wp-includes/script-loader.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 4b6d9de25fa11..9c63a0744e069 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -627,6 +627,7 @@ add_action( 'enqueue_block_editor_assets', 'wp_enqueue_block_editor_script_modules' ); add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' ); add_action( 'enqueue_block_editor_assets', '_wp_enqueue_auto_register_blocks' ); +add_action( 'enqueue_block_editor_assets', 'wp_declare_classic_block_necessary' ); add_action( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 42d42b3f8781d..b37cda289edc1 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2647,6 +2647,33 @@ function wp_enqueue_global_styles() { wp_add_global_styles_for_blocks(); } +/** + * Declares a flag that the Classic block is necessary for the current post. + * + * @since 7.1.0 + */ +function wp_declare_classic_block_necessary() { + global $post; + + /** + * Filters whether the Classic block should be available in the inserter. + * + * Defaults to false. Use this filter to opt in (globally or per post). + * + * @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. + */ + if ( ! (bool) apply_filters( 'wp_classic_block_supports_inserter', false, $post ) ) { + return; + } + + wp_add_inline_script( + 'wp-block-library', + 'window.__needsClassicBlock = true;', + 'before' + ); +} + /** * Checks if the editor scripts and styles for all registered block types * should be enqueued on the current screen. From 8a2e2bb87b61b93234d3347f736c51807dfcc064 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Wed, 6 May 2026 17:11:08 +0300 Subject: [PATCH 2/2] Add global $post to doc block --- src/wp-includes/script-loader.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index b37cda289edc1..09ccfbfd14a0f 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2650,6 +2650,8 @@ function wp_enqueue_global_styles() { /** * Declares a flag that the Classic block is necessary for the current post. * + * @global WP_Post $post Global post object. + * * @since 7.1.0 */ function wp_declare_classic_block_necessary() {