Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b5aaa44
Don't set ignoredHookedBlocks metadata upon read
ockham Feb 12, 2024
2e28810
Don't pass anchor_block by reference
ockham Feb 12, 2024
40fa3fb
Update PHPDoc
ockham Feb 12, 2024
1f0d087
Add new set_ignored_hooked_blocks_metadata() function
ockham Feb 12, 2024
c434d75
Whitespace
ockham Feb 12, 2024
b63d367
Fix first batch of unit tests
ockham Feb 12, 2024
36c0fc3
Fix remaining unit tests
ockham Feb 12, 2024
2358241
There can never be enough callbacks
ockham Feb 12, 2024
0330473
Tweak set_ignored_hooked_blocks_metadata to match callback signature
ockham Feb 12, 2024
e6eea6e
Wire it all up
ockham Feb 12, 2024
eb1daa1
Whitespace
ockham Feb 13, 2024
d057ece
Bail early
ockham Feb 13, 2024
ab6a8c9
Actually update post
ockham Feb 13, 2024
998147f
Use correct action
ockham Feb 13, 2024
1296344
Add action for template parts
ockham Feb 13, 2024
27724fc
Add note on action vs filter
ockham Feb 13, 2024
012004b
Clarify comment
ockham Feb 13, 2024
27a2ec8
Fix more unit tests
ockham Feb 13, 2024
12ccd0d
Start adding test coverage for set_ignored_hooked_blocks_metadata
ockham Feb 13, 2024
1128b5f
Add more test coverage and a small fix
ockham Feb 13, 2024
5817b49
Add test coverage for hooked block added by filter
ockham Feb 13, 2024
60b2732
Add test to cover context-aware filter
ockham Feb 13, 2024
61847cb
Remove obsolete comment about post_filtered_content
ockham Feb 13, 2024
712260f
Move set_ignored_hooked_blocks_metadata function definition below ins…
ockham Feb 13, 2024
7c7f01e
Inline get_hooked_block_markup
ockham Feb 13, 2024
f4f856b
Coding Standards in test
ockham Feb 13, 2024
7d43f21
Add test coverage to verify hooked blocks aren't added if ignored
ockham Feb 13, 2024
3c9aa4b
Move set_ignored_hooked_blocks_metadata_upon_rest_insert to block-tem…
ockham Feb 13, 2024
51832fe
Rename to inject_ignored_hooked_blocks_metadata_attributes
ockham Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inline get_hooked_block_markup
  • Loading branch information
ockham committed Feb 13, 2024
commit 7c7f01e99a342fc1bfd004877541aa7f6d797b02
41 changes: 7 additions & 34 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,38 +850,6 @@ function get_hooked_blocks() {
return $hooked_blocks;
}

/**
* Conditionally returns the markup for a given hooked block.
*
* Accepts three arguments: A hooked block, its type, and an anchor block.
* If the anchor block has already been processed, and the given hooked block type is in the list
* of ignored hooked blocks, an empty string is returned.
*
* The hooked block type is specified separately as it's possible that a filter might've modified
* the hooked block such that `$hooked_block['blockName']` does no longer reflect the original type.
*
* This function is meant for internal use only.
*
* @since 6.5.0
* @access private
*
* @param array $hooked_block The hooked block, represented as a parsed block array.
* @param string $hooked_block_type The type of the hooked block. This could be different from
* $hooked_block['blockName'], as a filter might've modified the latter.
* @param array $anchor_block The anchor block, represented as a parsed block array.
* @return string The markup for the given hooked block, or an empty string if the block is ignored.
*/
function get_hooked_block_markup( $hooked_block, $hooked_block_type, $anchor_block ) {
if (
isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) &&
in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'], true )
) {
return '';
}

return serialize_block( $hooked_block );
}

/**
* Returns the markup for blocks hooked to the given anchor block in a specific relative position.
*
Expand Down Expand Up @@ -940,8 +908,13 @@ function insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooke
$parsed_hooked_block = apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block, $relative_position, $parsed_anchor_block, $context );

// It's possible that the `hooked_block_{$hooked_block_type}` filter returned a block of a different type,
// so we need to pass the original $hooked_block_type as well.
$markup .= get_hooked_block_markup( $parsed_hooked_block, $hooked_block_type, $parsed_anchor_block );
// so we explicitly look for the original `$hooked_block_type` in the `ignoredHookedBlocks` metadata.
if (
! isset( $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ||
! in_array( $hooked_block_type, $parsed_anchor_block['attrs']['metadata']['ignoredHookedBlocks'], true )
) {
$markup .= serialize_block( $parsed_hooked_block );
}
}

return $markup;
Expand Down
100 changes: 0 additions & 100 deletions tests/phpunit/tests/blocks/getHookedBlockMarkup.php

This file was deleted.