Make WordPress Core


Ignore:
Timestamp:
07/02/2024 10:01:17 AM (10 months ago)
Author:
Bernhard Reiter
Message:

Block Hooks: Allow child insertion into Template Part block.

The Block Hooks mechanism was previously extended to allow insertion of a block as a Navigation block's first or last child. This was implemented by storing the ignoredHookedBlocks array in the corresponding wp_navigation post's post meta (instead of a metadata attribute on the anchor block).

This changeset extends that mechanism to Template Part blocks, by storing said metadata in the corresponding wp_template_part post's post meta, thus allowing extenders to use Block Hooks to insert a block as a Template Part block's first or last child, respectively.

Props tomjcafferkey, bernhard-reiter.
Fixes #60854.

File:
1 edited

Legend:

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

    r58578 r58614  
    10471047
    10481048/**
     1049 * Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the wrapper block.
     1050 *
     1051 * @since 6.7.0
     1052 * @access private
     1053 *
     1054 * @see remove_serialized_parent_block()
     1055 *
     1056 * @param string $serialized_block The serialized markup of a block and its inner blocks.
     1057 * @return string The serialized markup of the wrapper block.
     1058 */
     1059function extract_serialized_parent_block( $serialized_block ) {
     1060    $start = strpos( $serialized_block, '-->' ) + strlen( '-->' );
     1061    $end   = strrpos( $serialized_block, '<!--' );
     1062    return substr( $serialized_block, 0, $start ) . substr( $serialized_block, $end );
     1063}
     1064
     1065/**
    10491066 * Updates the wp_postmeta with the list of ignored hooked blocks where the inner blocks are stored as post content.
    10501067 * Currently only supports `wp_navigation` post types.
Note: See TracChangeset for help on using the changeset viewer.