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/src/wp-includes/default-filters.php

    r59415 r59523  
    193193add_filter( 'the_title', 'trim' );
    194194
     195add_filter( 'the_content', 'apply_block_hooks_to_content', 8 ); // BEFORE do_blocks().
    195196add_filter( 'the_content', 'do_blocks', 9 );
    196197add_filter( 'the_content', 'wptexturize' );
     
    761762
    762763// Update ignoredHookedBlocks postmeta for wp_navigation post type.
     764add_filter( 'rest_pre_insert_page', 'update_ignored_hooked_blocks_postmeta' );
     765add_filter( 'rest_pre_insert_post', 'update_ignored_hooked_blocks_postmeta' );
    763766add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' );
    764767
    765 // Inject hooked blocks into the wp_navigation post type REST response.
     768// Inject hooked blocks into the Posts endpoint REST response for some given post types.
     769add_filter( 'rest_prepare_page', 'insert_hooked_blocks_into_rest_response', 10, 2 );
     770add_filter( 'rest_prepare_post', 'insert_hooked_blocks_into_rest_response', 10, 2 );
    766771add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 );
    767772
Note: See TracChangeset for help on using the changeset viewer.