Make WordPress Core


Ignore:
Timestamp:
09/26/2023 11:47:18 AM (3 years ago)
Author:
Bernhard Reiter
Message:

Blocks: Have get_hooked_blocks() return blocks grouped by position.

All existing calls of get_hooked_blocks() in non-test code are currently wrapped in an extra array_keys() call. This changeset absorbs that logic into the function and changes the structure of the return value accordingly.

Furthermore, this allows us to remove the extra $relative_position argument (introduced in [56673]) from the function again, as the same data can now be simply fetched via array access.

Props gziolo, spacedmonkey, mukesh27.
See #59383.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/blockHooks.php

    r56673 r56704  
    7171                $this->assertSame(
    7272                        array(
    73                                 'tests/injected-one' => 'before',
    74                                 'tests/injected-two' => 'before',
     73                                'before' => array(
     74                                        'tests/injected-one',
     75                                        'tests/injected-two',
     76                                ),
    7577                        ),
    7678                        get_hooked_blocks( 'tests/hooked-at-before' ),
     
    7981                $this->assertSame(
    8082                        array(
    81                                 'tests/injected-one' => 'after',
    82                                 'tests/injected-two' => 'after',
     83                                'after' => array(
     84                                        'tests/injected-one',
     85                                        'tests/injected-two',
     86                                ),
    8387                        ),
    8488                        get_hooked_blocks( 'tests/hooked-at-after' ),
     
    8791                $this->assertSame(
    8892                        array(
    89                                 'tests/injected-two' => 'first_child',
     93                                'first_child' => array(
     94                                        'tests/injected-two',
     95                                ),
    9096                        ),
    9197                        get_hooked_blocks( 'tests/hooked-at-first-child' ),
     
    94100                $this->assertSame(
    95101                        array(
    96                                 'tests/injected-two' => 'last_child',
     102                                'last_child' => array(
     103                                        'tests/injected-two',
     104                                ),
    97105                        ),
    98106                        get_hooked_blocks( 'tests/hooked-at-last-child' ),
     
    101109                $this->assertSame(
    102110                        array(
    103                                 'tests/injected-one' => 'before',
    104                                 'tests/injected-two' => 'after',
     111                                'before' => array(
     112                                        'tests/injected-one',
     113                                ),
     114                                'after'  => array(
     115                                        'tests/injected-two',
     116                                ),
    105117                        ),
    106118                        get_hooked_blocks( 'tests/hooked-at-before-and-after' ),
    107119                        'block hooked before one block and after another'
    108120                );
    109                 $this->assertSame(
    110                         array(
    111                                 'tests/injected-one' => 'before',
    112                         ),
    113                         get_hooked_blocks( 'tests/hooked-at-before-and-after', 'before' ),
    114                         'block hooked before one block and after another, filtered for before'
    115                 );
    116121        }
    117122}
Note: See TracChangeset for help on using the changeset viewer.