Make WordPress Core


Ignore:
Timestamp:
03/03/2025 06:06:16 PM (20 months ago)
Author:
joemcgill
Message:

Editor: Update packages for 6.8 Beta 1.

Syncs @wordpress/* packages to the 'latest' npm tag.

Props mamaduka, joemcgill, desrosj.
See #62887.

File:
1 edited

Legend:

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

    r59775 r59906  
    242242                        $blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
    243243
    244                         // Run Block Hooks algorithm to inject hooked blocks.
    245                         $markup         = block_core_navigation_insert_hooked_blocks( $blocks, $navigation_post );
    246                         $root_nav_block = parse_blocks( $markup )[0];
    247 
    248                         $blocks = isset( $root_nav_block['innerBlocks'] ) ? $root_nav_block['innerBlocks'] : $blocks;
     244                        // Re-serialize, and run Block Hooks algorithm to inject hooked blocks.
     245                        // TODO: See if we can move the apply_block_hooks_to_content_from_post_object() call
     246                        // before the parse_blocks() call further above, to avoid the extra serialization/parsing.
     247                        $markup = serialize_blocks( $blocks );
     248                        $markup = apply_block_hooks_to_content_from_post_object( $markup, $navigation_post );
     249                        $blocks = parse_blocks( $markup );
    249250
    250251                        // TODO - this uses the full navigation block attributes for the
    … …  
    10781079                // Run Block Hooks algorithm to inject hooked blocks.
    10791080                // We have to run it here because we need the post ID of the Navigation block to track ignored hooked blocks.
    1080                 $markup = block_core_navigation_insert_hooked_blocks( $fallback_blocks, $navigation_post );
    1081                 $blocks = parse_blocks( $markup );
    1082 
    1083                 if ( isset( $blocks[0]['innerBlocks'] ) ) {
    1084                         $fallback_blocks = $blocks[0]['innerBlocks'];
    1085                 }
     1081                // TODO: See if we can move the apply_block_hooks_to_content_from_post_object() call
     1082                // before the parse_blocks() call further above, to avoid the extra serialization/parsing.
     1083                $markup          = serialize_blocks( $fallback_blocks );
     1084                $markup          = apply_block_hooks_to_content_from_post_object( $markup, $navigation_post );
     1085                $fallback_blocks = parse_blocks( $markup );
    10861086        }
    10871087
    … …  
    14371437        return null;
    14381438}
    1439 
    1440 /**
    1441  * Mock a parsed block for the Navigation block given its inner blocks and the `wp_navigation` post object.
    1442  * The `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is queried to add the `metadata.ignoredHookedBlocks` attribute.
    1443  *
    1444  * @since 6.5.0
    1445  *
    1446  * @param array   $inner_blocks Parsed inner blocks of a Navigation block.
    1447  * @param WP_Post $post         `wp_navigation` post object corresponding to the block.
    1448  *
    1449  * @return array the normalized parsed blocks.
    1450  */
    1451 function block_core_navigation_mock_parsed_block( $inner_blocks, $post ) {
    1452         $attributes = array();
    1453 
    1454         if ( isset( $post->ID ) ) {
    1455                 $ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true );
    1456                 if ( ! empty( $ignored_hooked_blocks ) ) {
    1457                         $ignored_hooked_blocks  = json_decode( $ignored_hooked_blocks, true );
    1458                         $attributes['metadata'] = array(
    1459                                 'ignoredHookedBlocks' => $ignored_hooked_blocks,
    1460                         );
    1461                 }
    1462         }
    1463 
    1464         $mock_anchor_parent_block = array(
    1465                 'blockName'    => 'core/navigation',
    1466                 'attrs'        => $attributes,
    1467                 'innerBlocks'  => $inner_blocks,
    1468                 'innerContent' => array_fill( 0, count( $inner_blocks ), null ),
    1469         );
    1470 
    1471         return $mock_anchor_parent_block;
    1472 }
    1473 
    1474 /**
    1475  * Insert hooked blocks into a Navigation block.
    1476  *
    1477  * Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object,
    1478  * this function inserts hooked blocks into it, and returns the serialized inner blocks in a
    1479  * mock Navigation block wrapper.
    1480  *
    1481  * If there are any hooked blocks that need to be inserted as the Navigation block's first or last
    1482  * children, the `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is checked to see if any
    1483  * of those hooked blocks should be exempted from insertion.
    1484  *
    1485  * @since 6.5.0
    1486  *
    1487  * @param array   $inner_blocks Parsed inner blocks of a Navigation block.
    1488  * @param WP_Post $post         `wp_navigation` post object corresponding to the block.
    1489  * @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any.
    1490  */
    1491 function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
    1492         $mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );
    1493 
    1494         $mock_navigation_block_markup = serialize_block( $mock_navigation_block );
    1495         return apply_block_hooks_to_content( $mock_navigation_block_markup, $post, 'insert_hooked_blocks' );
    1496 }
Note: See TracChangeset for help on using the changeset viewer.