diff --git a/lib/client-assets.php b/lib/client-assets.php index db1051bb43d33e..140e189f33a2c5 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -87,23 +87,15 @@ function gutenberg_override_translation_file( $file, $handle ) { add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 ); /** - * Handle special case dependencies for wp-block-library that depend on runtime conditions. - * - * This adds the 'editor' dependency conditionally based on experiments and classic block requirements. - * All other script registrations are handled by the auto-generated build/scripts.php file. + * Adds the 'editor' dependency to wp-block-library, required by the Classic block. * * @param WP_Scripts $scripts WP_Scripts instance. */ function gutenberg_register_block_library_script_special_case( $scripts ) { $handle = 'wp-block-library'; $script = $scripts->query( $handle, 'registered' ); - if ( - ! gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) || - gutenberg_post_being_edited_requires_classic_block() - ) { - if ( ! in_array( 'editor', $script->deps, true ) ) { - $script->deps[] = 'editor'; - } + if ( ! in_array( 'editor', $script->deps, true ) ) { + $script->deps[] = 'editor'; } } add_action( 'wp_default_scripts', 'gutenberg_register_block_library_script_special_case', 11 ); diff --git a/lib/experimental/disable-tinymce.php b/lib/experimental/disable-tinymce.php index 6ae38716eac435..3cdff69673a70d 100644 --- a/lib/experimental/disable-tinymce.php +++ b/lib/experimental/disable-tinymce.php @@ -9,7 +9,7 @@ * Render a variable that we'll use to declare that the editor will need the classic block. */ function gutenberg_declare_classic_block_necessary() { - if ( ! gutenberg_post_being_edited_requires_classic_block() ) { + if ( ! gutenberg_classic_block_supports_inserter() ) { return; } echo ''; @@ -17,46 +17,28 @@ function gutenberg_declare_classic_block_necessary() { add_action( 'admin_print_footer_scripts', 'gutenberg_declare_classic_block_necessary', 20 ); /** - * Whether the current editor contains a classic block instance. + * Whether the Classic block should be available in the inserter. * - * @return bool True if the editor contains a classic block, false otherwise. + * @return bool True if the Classic block should be in the inserter. */ -function gutenberg_post_being_edited_requires_classic_block() { - if ( ! is_admin() ) { - return false; - } - - // Continue only if we're in the post editor. - if ( empty( $_GET['post'] ) || empty( $_GET['action'] ) || 'edit' !== $_GET['action'] ) { - return false; - } - - // Bail if for some reason the post isn't found. - $current_post = get_post( absint( $_GET['post'] ) ); - if ( ! $current_post ) { - return false; - } - - // Check if block editor is disabled by "Classic Editor" or another plugin. +function gutenberg_classic_block_supports_inserter() { + $post = null; if ( - function_exists( 'use_block_editor_for_post_type' ) && - ! use_block_editor_for_post_type( $current_post->post_type ) + is_admin() && + ! empty( $_GET['post'] ) && + ! empty( $_GET['action'] ) && + 'edit' === $_GET['action'] ) { - return true; - } - - $content = $current_post->post_content; - if ( empty( $content ) ) { - return false; - } - - $parsed_blocks = parse_blocks( $content ); - foreach ( $parsed_blocks as $block ) { - $is_freeform_block = empty( $block['blockName'] ) || 'core/freeform' === $block['blockName']; - if ( $is_freeform_block && strlen( trim( $block['innerHTML'] ) ) > 0 ) { - return true; - } + $post = get_post( absint( $_GET['post'] ) ); } - return false; + /** + * 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. + */ + return (bool) apply_filters( 'gutenberg_classic_block_supports_inserter', false, $post ); }