Make WordPress Core


Ignore:
Timestamp:
12/17/2024 10:35:17 AM (6 months ago)
Author:
Bernhard Reiter
Message:

Block Hooks: Enable for post content.

Block Hooks were previously only applied to layout elements such as templates, template parts, patterns, and navigation menus -- things that are edited in the Site Editor.

This changeset enables Block Hooks in post content. The parity between frontend and editor is preserved: Blocks inserted by Block Hooks are visible both on the frontend and in the editor, and any customizations made by the user are respected on the frontend.

This is possible thanks to setting the metadata.ignoredHookedBlocks attribute on anchor blocks (a technique first introduced in [57594]). For first child and last child insertion into a Post Content block, the corresponding post object's _wp_ignored_hooked_blocks post meta is set.

Props bernhard-reiter, gziolo, jonsurrell, karolmanijak, leewillis77.
Fixes #61074.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/applyBlockHooksToContent.php

    r59124 r59523  
    9393
    9494    /**
     95     * @ticket 61074
     96     */
     97    public function test_apply_block_hooks_to_content_with_context_set_to_null() {
     98        $content = '<!-- wp:tests/anchor-block /-->';
     99
     100        /*
     101         * apply_block_hooks_to_content() will fall back to the global $post object (via get_post())
     102         * if the $context parameter is null. However, we'd also like to ensure that the function
     103         * works as expected even when get_post() returns null.
     104         */
     105        $this->assertNull( get_post() );
     106
     107        $actual = apply_block_hooks_to_content( $content, null, 'insert_hooked_blocks' );
     108        $this->assertSame(
     109            '<!-- wp:tests/anchor-block /--><!-- wp:tests/hooked-block /-->',
     110            $actual
     111        );
     112    }
     113
     114    /**
    95115     * @ticket 61902
    96116     */
Note: See TracChangeset for help on using the changeset viewer.