mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Blocks: Call get_hooked_blocks only once per template/part/pattern.
Prior to this changeset, `get_hooked_blocks` was called four times ''for every parsed block'' in each template, template part, and pattern. With this changeset applied, `get_hooked_blocks` is called only once per template, template part, or pattern. Additionally, `get_hooked_blocks` is called only once when returning the list of all registered patterns. (The latter modification brings the implementation closer to its state prior to Block Hooks.) Finally, when there are no registered hooked blocks or `hooked_block_types` filters, parsing, hooked block insertion, and re-serializing is skipped altogether. Props gziolo, flixos90, joemcgill, dmsnell, spacedmonkey, hellofromtonya. Fixes #59383. git-svn-id: https://develop.svn.wordpress.org/trunk@56805 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -62,7 +62,7 @@ class Tests_Blocks_GetHookedBlocks extends WP_UnitTestCase {
|
||||
* @covers ::get_hooked_blocks
|
||||
*/
|
||||
public function test_get_hooked_blocks_no_match_found() {
|
||||
$result = get_hooked_blocks( 'tests/no-hooked-blocks' );
|
||||
$result = get_hooked_blocks();
|
||||
|
||||
$this->assertSame( array(), $result );
|
||||
}
|
||||
@@ -98,53 +98,38 @@ class Tests_Blocks_GetHookedBlocks extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'before' => array(
|
||||
'tests/injected-one',
|
||||
'tests/injected-two',
|
||||
'tests/hooked-at-before' => array(
|
||||
'before' => array(
|
||||
'tests/injected-one',
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
'tests/hooked-at-after' => array(
|
||||
'after' => array(
|
||||
'tests/injected-one',
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
'tests/hooked-at-before-and-after' => array(
|
||||
'before' => array(
|
||||
'tests/injected-one',
|
||||
),
|
||||
'after' => array(
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
'tests/hooked-at-first-child' => array(
|
||||
'first_child' => array(
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
'tests/hooked-at-last-child' => array(
|
||||
'last_child' => array(
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
),
|
||||
get_hooked_blocks( 'tests/hooked-at-before' ),
|
||||
'block hooked at the before position'
|
||||
);
|
||||
$this->assertSame(
|
||||
array(
|
||||
'after' => array(
|
||||
'tests/injected-one',
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
get_hooked_blocks( 'tests/hooked-at-after' ),
|
||||
'block hooked at the after position'
|
||||
);
|
||||
$this->assertSame(
|
||||
array(
|
||||
'first_child' => array(
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
get_hooked_blocks( 'tests/hooked-at-first-child' ),
|
||||
'block hooked at the first child position'
|
||||
);
|
||||
$this->assertSame(
|
||||
array(
|
||||
'last_child' => array(
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
get_hooked_blocks( 'tests/hooked-at-last-child' ),
|
||||
'block hooked at the last child position'
|
||||
);
|
||||
$this->assertSame(
|
||||
array(
|
||||
'before' => array(
|
||||
'tests/injected-one',
|
||||
),
|
||||
'after' => array(
|
||||
'tests/injected-two',
|
||||
),
|
||||
),
|
||||
get_hooked_blocks( 'tests/hooked-at-before-and-after' ),
|
||||
'block hooked before one block and after another'
|
||||
get_hooked_blocks()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user