Changeset 57790 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 03/07/2024 02:10:31 PM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r57771 r57790 1433 1433 return $template_hierarchy; 1434 1434 } 1435 1435 1436 /** 1436 1437 * Inject ignoredHookedBlocks metadata attributes into a template or template part. 1437 1438 * 1438 * Given a `wp_template` or `wp_template_part` post object, locate all blocks that have 1439 * Given an object that represents a `wp_template` or `wp_template_part` post object 1440 * prepared for inserting or updating the database, locate all blocks that have 1439 1441 * hooked blocks, and inject a `metadata.ignoredHookedBlocks` attribute into the anchor 1440 1442 * blocks to reflect the latter. 1441 1443 * 1442 * @param WP_Post $post A post object with post type set to `wp_template` or `wp_template_part`. 1443 * @return WP_Post The updated post object. 1444 */ 1445 function inject_ignored_hooked_blocks_metadata_attributes( $post ) { 1444 * @since 6.5.0 1445 * @access private 1446 * 1447 * @param stdClass $post An object representing a template or template part 1448 * prepared for inserting or updating the database. 1449 * @param WP_REST_Request $request Request object. 1450 * @return stdClass The updated object representing a template or template part. 1451 */ 1452 function inject_ignored_hooked_blocks_metadata_attributes( $post, $request ) { 1453 $filter_name = current_filter(); 1454 if ( ! str_starts_with( $filter_name, 'rest_pre_insert_' ) ) { 1455 return $post; 1456 } 1457 $post_type = str_replace( 'rest_pre_insert_', '', $filter_name ); 1458 1446 1459 $hooked_blocks = get_hooked_blocks(); 1447 1460 if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) { 1448 return ;1461 return $post; 1449 1462 } 1450 1463 … … 1453 1466 // To that end, we need to suppress hooked blocks from getting inserted into the template. 1454 1467 add_filter( 'hooked_block_types', '__return_empty_array', 99999, 0 ); 1455 $template = _build_block_template_result_from_post( $post );1468 $template = $request['id'] ? get_block_template( $request['id'], $post_type ) : null; 1456 1469 remove_filter( 'hooked_block_types', '__return_empty_array', 99999 ); 1457 1470 … … 1459 1472 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template, 'set_ignored_hooked_blocks_metadata' ); 1460 1473 1461 $blocks = parse_blocks( $ template->content );1474 $blocks = parse_blocks( $post->post_content ); 1462 1475 $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 1463 1476 1464 wp_update_post( 1465 array( 1466 'ID' => $post->ID, 1467 'post_content' => $content, 1468 ) 1469 ); 1470 } 1477 $post->post_content = $content; 1478 return $post; 1479 }
Note: See TracChangeset
for help on using the changeset viewer.