Make WordPress Core

Changeset 62652


Ignore:
Timestamp:
07/07/2026 05:58:54 AM (2 months ago)
Author:
tyxla
Message:

Editor: Restore Classic block in the inserter.

Revert the Classic block inserter-hiding work introduced in [62546], so the
Classic (core/freeform) block is once again available in the inserter by
default.

This removes:

  • The wp_declare_classic_block_necessary() function and its enqueue_block_editor_assets action hook in script-loader.php and default-filters.php.
  • The wp_classic_block_supports_inserter filter, which never shipped in a WordPress release and can therefore be removed cleanly.
  • The associated PHPUnit tests in tests/phpunit/tests/dependencies/scripts.php.

This keeps Core in sync with the corresponding Gutenberg revert in
https://github.com/WordPress/gutenberg/pull/79894.

Props tyxla, youknowriad, mukesh27.
See #65166.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r62649 r62652  
    645645add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' );
    646646add_action( 'enqueue_block_editor_assets', '_wp_enqueue_auto_register_blocks' );
    647 add_action( 'enqueue_block_editor_assets', 'wp_declare_classic_block_necessary' );
    648647add_action( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
    649648add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
  • trunk/src/wp-includes/script-loader.php

    r62546 r62652  
    26482648
    26492649/**
    2650  * Declares a flag that the Classic block is necessary for the current post.
    2651  *
    2652  * @since 7.1.0
    2653  * @access private
    2654  */
    2655 function wp_declare_classic_block_necessary(): void {
    2656         /**
    2657          * Filters whether the Classic block should be available in the inserter.
    2658          *
    2659          * Defaults to false. Use this filter to opt in (globally or per post).
    2660          *
    2661          * @param bool         $supports_inserter Whether the Classic block is available in the inserter.
    2662          * @param WP_Post|null $post              The post being edited, or null if not in the post editor.
    2663          */
    2664         if ( ! (bool) apply_filters( 'wp_classic_block_supports_inserter', false, get_post() ) ) {
    2665                 return;
    2666         }
    2667 
    2668         wp_add_inline_script(
    2669                 'wp-block-library',
    2670                 'window.__needsClassicBlock = true;',
    2671                 'before'
    2672         );
    2673 }
    2674 
    2675 /**
    26762650 * Checks if the editor scripts and styles for all registered block types
    26772651 * should be enqueued on the current screen.
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r62546 r62652  
    45444544
    45454545        /**
    4546          * Tests that the Classic block is hidden from the inserter by default.
    4547          *
    4548          * @ticket 65166
    4549          *
    4550          * @covers ::wp_declare_classic_block_necessary
    4551          */
    4552         public function test_wp_declare_classic_block_necessary_does_nothing_by_default() {
    4553                 wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );
    4554 
    4555                 wp_declare_classic_block_necessary();
    4556 
    4557                 $this->assertFalse(
    4558                         wp_scripts()->get_data( 'wp-block-library', 'before' ),
    4559                         'No inline script should be enqueued when the filter is not used.'
    4560                 );
    4561         }
    4562 
    4563         /**
    4564          * Tests that the Classic block can be opted into the inserter via the filter.
    4565          *
    4566          * @ticket 65166
    4567          *
    4568          * @covers ::wp_declare_classic_block_necessary
    4569          */
    4570         public function test_wp_declare_classic_block_necessary_enqueues_flag_when_filter_enabled() {
    4571                 wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );
    4572                 add_filter( 'wp_classic_block_supports_inserter', '__return_true' );
    4573 
    4574                 wp_declare_classic_block_necessary();
    4575 
    4576                 $before = wp_scripts()->get_data( 'wp-block-library', 'before' );
    4577                 $this->assertIsArray(
    4578                         $before,
    4579                         'An inline script should be enqueued when the filter opts in.'
    4580                 );
    4581                 $this->assertContains(
    4582                         'window.__needsClassicBlock = true;',
    4583                         $before,
    4584                         'The Classic block flag should be added to the wp-block-library inline scripts.'
    4585                 );
    4586         }
    4587 
    4588         /**
    4589          * Tests that the current post is passed to the filter.
    4590          *
    4591          * @ticket 65166
    4592          *
    4593          * @covers ::wp_declare_classic_block_necessary
    4594          */
    4595         public function test_wp_declare_classic_block_necessary_passes_post_to_filter() {
    4596                 wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );
    4597 
    4598                 $post_id         = self::factory()->post->create();
    4599                 $GLOBALS['post'] = get_post( $post_id );
    4600 
    4601                 $filter_post = false;
    4602                 add_filter(
    4603                         'wp_classic_block_supports_inserter',
    4604                         static function ( $supports_inserter, $post ) use ( &$filter_post ) {
    4605                                 $filter_post = $post;
    4606                                 return $supports_inserter;
    4607                         },
    4608                         10,
    4609                         2
    4610                 );
    4611 
    4612                 wp_declare_classic_block_necessary();
    4613 
    4614                 $this->assertInstanceOf( WP_Post::class, $filter_post, 'The post should be passed to the filter.' );
    4615                 $this->assertSame( $post_id, $filter_post->ID, 'The current post should be passed to the filter.' );
    4616         }
    4617 
    4618         /**
    46194546         * Normalizes markup for snapshot.
    46204547         *
Note: See TracChangeset for help on using the changeset viewer.