Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#59424 closed enhancement

Blocks: Introduce filter to allow easy addition of hooked blocks — at Initial Version

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by: bernhard-reiter's profile Bernhard Reiter
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch has-unit-tests commit
Focuses: Cc:

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
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 );

Change History (0)

Note: See TracTickets for help on using tickets.