Make WordPress Core


Ignore:
Timestamp:
02/13/2024 03:10:21 PM (4 months ago)
Author:
Bernhard Reiter
Message:

Block Hooks: Set ignoredHookedBlocks metadata upon saving.

Decouple hooked blocks insertion from setting the metadata.ignoredHookedBlocks attribute on anchor blocks, and perform the latter step upon saving a template or template part to the database. This ensures that anchor blocks that have been newly added to a template (or part) on the client side will also get ignoredHookedBlocks metadata set correctly, thus preserving editor/front-end parity. Hooked block insertion, on the other hand, will continue to happen upon reading a template (or part).

Props gziolo, tomjcafferkey.
Fixes #60506.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-templates/buildBlockTemplateResultFromPost.php

    r57594 r57627  
    1919        if ( $registry->is_registered( 'tests/my-block' ) ) {
    2020            $registry->unregister( 'tests/my-block' );
     21        }
     22
     23        if ( $registry->is_registered( 'tests/ignored' ) ) {
     24            $registry->unregister( 'tests/ignored' );
    2125        }
    2226
     
    6872    /**
    6973     * @ticket 59646
     74     * @ticket 60506
    7075     */
    7176    public function test_should_inject_hooked_block_into_template() {
     
    8489        );
    8590        $this->assertStringStartsWith( '<!-- wp:tests/my-block /-->', $template->content );
    86         $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $template->content );
    8791    }
    8892
    8993    /**
    9094     * @ticket 59646
     95     * @ticket 60506
    9196     */
    9297    public function test_should_inject_hooked_block_into_template_part() {
     
    105110        );
    106111        $this->assertStringEndsWith( '<!-- wp:tests/my-block /-->', $template_part->content );
    107         $this->assertStringContainsString( '"metadata":{"ignoredHookedBlocks":["tests/my-block"]}', $template_part->content );
     112    }
     113
     114    /**
     115     * @ticket 59646
     116     * @ticket 60506
     117     */
     118    public function test_should_not_inject_ignored_hooked_block_into_template() {
     119        register_block_type(
     120            'tests/ignored',
     121            array(
     122                'block_hooks' => array(
     123                    'core/heading' => 'after',
     124                ),
     125            )
     126        );
     127
     128        $template = _build_block_template_result_from_post(
     129            self::$template_post,
     130            'wp_template'
     131        );
     132        $this->assertStringNotContainsString( '<!-- wp:tests/ignored /-->', $template->content );
     133    }
     134
     135    /**
     136     * @ticket 59646
     137     * @ticket 60506
     138     */
     139    public function test_should_not_inject_ignored_hooked_block_into_template_part() {
     140        register_block_type(
     141            'tests/ignored',
     142            array(
     143                'block_hooks' => array(
     144                    'core/heading' => 'after',
     145                ),
     146            )
     147        );
     148
     149        $template_part = _build_block_template_result_from_post(
     150            self::$template_part_post,
     151            'wp_template_part'
     152        );
     153        $this->assertStringNotContainsString( '<!-- wp:tests/ignored /-->', $template_part->content );
    108154    }
    109155}
Note: See TracChangeset for help on using the changeset viewer.