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..f26fae4c3d598 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2646,6 +2646,31 @@ 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(): void { + /** + * 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, get_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.