From 511ae9656b2672c5b5642bca0ef4a68455f7629e 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/4] 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 a4ecf677e2af1..a8d74663c9160 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 134d86c26a08a..78f9975424306 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2646,6 +2646,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 6597ebb703581ee6d561f401e0b73ec7a2b6d2a1 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/4] 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 78f9975424306..b91966eaaf177 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2649,6 +2649,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() { From 54dafcdf21989c95447672f737be97a1db9319f8 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Sun, 24 May 2026 17:04:07 +0200 Subject: [PATCH 3/4] Use get_post() instead of global $post Co-authored-by: Weston Ruter --- src/wp-includes/script-loader.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index b91966eaaf177..44fd7dc003955 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2649,13 +2649,10 @@ 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() { - global $post; - +function wp_declare_classic_block_necessary(): void { /** * Filters whether the Classic block should be available in the inserter. * @@ -2664,7 +2661,7 @@ function wp_declare_classic_block_necessary() { * @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 ) ) { + if ( ! (bool) apply_filters( 'wp_classic_block_supports_inserter', false, get_post() ) ) { return; } From 5a18af9d279f53201aa67e9711308f69aae0109d Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Sun, 24 May 2026 17:12:02 +0200 Subject: [PATCH 4/4] Remove stray blank line from doc block --- src/wp-includes/script-loader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 44fd7dc003955..f26fae4c3d598 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2649,7 +2649,6 @@ function wp_enqueue_global_styles() { /** * Declares a flag that the Classic block is necessary for the current post. * - * * @since 7.1.0 */ function wp_declare_classic_block_necessary(): void {