Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block is no longer registered conditionally, so this dependency doesn't need to be conditional either - editor is required whenever the Classic block can render, which is now always.

! 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 );
Expand Down
56 changes: 19 additions & 37 deletions lib/experimental/disable-tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,36 @@
* 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 '<script type="text/javascript">window.wp.needsClassicBlock = true;</script>';
}
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 );
}
Loading