[wp-trac] [WordPress Trac] #59424: Blocks: Introduce filter to allow easy addition of hooked blocks

WordPress Trac noreply at wordpress.org
Thu Sep 21 16:58:58 UTC 2023


#59424: Blocks: Introduce filter to allow easy addition of hooked blocks
--------------------------------------+------------------------------
 Reporter:  Bernhard Reiter           |       Owner:  Bernhard Reiter
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  6.4
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------
Description changed by Bernhard Reiter:

Old description:

> As a follow-up to [56649], it would be good to introduce a filter that
> allows even easier conditional addition (or removal) of hooked blocks for
> a given anchor block and relative position.
>
> Something along the following lines:
>
> {{{#!php
> <?php
> function insert_shopping_cart_hooked_block( $hooked_blocks, $position,
> $anchor_block, $context ) {
>         if ( 'after' === $position && 'core/navigation' && $anchor_block
> && /** $context is header template part **/ ) {
>                 $hooked_blocks[] = 'mycommerce/shopping-cart';
>         }
>         return $hooked_blocks;
> }
> add_filter( 'hooked_block_types', 'insert_shopping_cart_hooked_block',
> 10, 4 );
> }}}

New description:

 As a follow-up to [56649], it would be good to introduce a filter that
 allows even easier conditional addition (or removal) of hooked blocks for
 a given anchor block and relative position.

 Something along the following lines:

 {{{#!php
 <?php
 function insert_shopping_cart_hooked_block( $hooked_blocks, $position,
 $anchor_block, $context ) {
         if ( 'after' === $position && 'core/navigation' === $anchor_block
 && /** $context is header template part **/ ) {
                 $hooked_blocks[] = 'mycommerce/shopping-cart';
         }
         return $hooked_blocks;
 }
 add_filter( 'hooked_block_types', 'insert_shopping_cart_hooked_block', 10,
 4 );
 }}}

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59424#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list