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..09ccfbfd14a0f 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2647,6 +2647,35 @@ function wp_enqueue_global_styles() { wp_add_global_styles_for_blocks(); } +/** + * 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; + + /** + * 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.