Changeset 57814 for trunk/src/wp-includes/blocks/navigation.php
- Timestamp:
- 03/12/2024 02:06:51 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/navigation.php
r57760 r57814 544 544 * Gets the nav element directives. 545 545 * 546 * @param bool $is_interactive Whether the block is interactive. 547 * @param array $attributes The block attributes. 546 * @param bool $is_interactive Whether the block is interactive. 548 547 * @return string the directives for the navigation element. 549 548 */ … … 1459 1458 * Updates the post meta with the list of ignored hooked blocks when the navigation is created or updated via the REST API. 1460 1459 * 1461 * @param WP_Post $post Post object. 1460 * @access private 1461 * @since 6.5.0 1462 * 1463 * @param stdClass $post Post object. 1464 * @return stdClass The updated post object. 1462 1465 */ 1463 1466 function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) { 1464 // We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into 1465 // all anchor blocks. For the root level, we create a mock Navigation and extract them from there. 1467 /* 1468 * We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into 1469 * all anchor blocks. For the root level, we create a mock Navigation and extract them from there. 1470 */ 1466 1471 $blocks = parse_blocks( $post->post_content ); 1467 $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, $post ); 1472 1473 /* 1474 * Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that 1475 * we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be 1476 * used as context for hooked blocks insertion). 1477 * We thus have to look it up from the DB,based on `$post->ID`. 1478 */ 1479 $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, get_post( $post->ID ) ); 1468 1480 1469 1481 $root_nav_block = parse_blocks( $markup )[0]; … … 1481 1493 } 1482 1494 1483 $serialized_inner_blocks = block_core_navigation_remove_serialized_parent_block( $markup ); 1484 1485 wp_update_post( 1486 array( 1487 'ID' => $post->ID, 1488 'post_content' => $serialized_inner_blocks, 1489 ) 1490 ); 1491 } 1492 1493 // Before adding our filter, we verify if it's already added in Core. 1494 // However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". 1495 // Therefore, we concatenate the Core's function name to circumvent this prefix for our check. 1496 $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; 1497 1498 // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 1499 // that are not present in Gutenberg's WP 6.5 compatibility layer. 1500 if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) { 1501 add_action( 'rest_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10, 3 ); 1495 $post->post_content = block_core_navigation_remove_serialized_parent_block( $markup ); 1496 return $post; 1497 } 1498 1499 /* 1500 * Before adding our filter, we verify if it's already added in Core. 1501 * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". 1502 * Therefore, we concatenate the Core's function name to circumvent this prefix for our check. 1503 */ 1504 $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found 1505 1506 /* 1507 * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 1508 * that are not present in Gutenberg's WP 6.5 compatibility layer. 1509 */ 1510 if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) { 1511 add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta' ); 1512 } 1513 1514 /* 1515 * Previous versions of Gutenberg were attaching the block_core_navigation_update_ignore_hooked_blocks_meta 1516 * function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_). 1517 * To avoid collisions, we need to remove the filter from that action if it's present. 1518 */ 1519 if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) { 1520 remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ); 1502 1521 } 1503 1522 … … 1507 1526 * @param WP_REST_Response $response The response object. 1508 1527 * @param WP_Post $post Post object. 1509 * @param WP_REST_Request $request Request object.1510 1528 * @return WP_REST_Response The response object. 1511 1529 */ … … 1526 1544 } 1527 1545 1528 // Before adding our filter, we verify if it's already added in Core. 1529 // However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". 1530 // Therefore, we concatenate the Core's function name to circumvent this prefix for our check. 1546 /* 1547 * Before adding our filter, we verify if it's already added in Core. 1548 * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". 1549 * Therefore, we concatenate the Core's function name to circumvent this prefix for our check. 1550 */ 1531 1551 $rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response'; 1532 1552 1533 // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 1534 // that are not present in Gutenberg's WP 6.5 compatibility layer. 1553 /* 1554 * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 1555 * that are not present in Gutenberg's WP 6.5 compatibility layer. 1556 */ 1535 1557 if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) { 1536 1558 add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
Note: See TracChangeset
for help on using the changeset viewer.