[wp-trac] [WordPress Trac] #54684: Add ability to filter blocks in WP_Block_List

WordPress Trac noreply at wordpress.org
Sat Dec 25 12:18:09 UTC 2021


#54684: Add ability to filter blocks in WP_Block_List
------------------------------------+-----------------------------
 Reporter:  afragen                 |       Owner:  (none)
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  5.9
Component:  Menus                   |     Version:  trunk
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:  administration
------------------------------------+-----------------------------
Changes (by audrasjb):

 * keywords:  has-patch => has-patch dev-feedback


Comment:

 Hi, I tested the patch and it looks like it works fine since I'm able to
 override the default value using the following code:

 {{{#!php
 <?php
 add_filter( 'block_list_blocks', function( $blocks ) {
         wp_die( var_export( $blocks ) );
         return $blocks;
 }, 10, 1 );

 /* Returns:
 array (
         0 => array (
                 'blockName' => 'core/navigation-link',
                 'attrs' => array (
                         'label' => 'Page d’exemple',
                         'type' => 'page',
                         'id' => 2,
                         'url' =>
 'http://localhost:8888/552/wordpress-10/page-d-exemple/',
                         'kind' => 'post-type',
                         'isTopLevelLink' => true,
                 ),
                 'innerBlocks' => array ( ),
                 'innerHTML' => '',
                 'innerContent' => array ( ),
         ),
 )
 */

 add_filter( 'block_list_blocks', function( $blocks ) {
         $blocks[0]['attrs'] = array(
                 'label' => 'My page One',
                 'type'  => 'page',
                 'id'    => 3,
                 'url'   =>
 'http://localhost:8888/552/wordpress-10/page-d-exemple/',
                 'kind'  => 'post-type',
                 'isTopLevelLink' => 1
         );
         wp_die( var_export( $blocks ) );
         return $blocks;
 }, 10, 1 );

 /* Returns:
 array (
         0 => array (
                 'blockName' => 'core/navigation-link',
                 'attrs' => array (
                         'label' => 'My page One',
                         'type' => 'page',
                         'id' => 3,
                         'url' =>
 'http://localhost:8888/552/wordpress-10/page-d-exemple/',
                         'kind' => 'post-type',
                         'isTopLevelLink' => 1,
                 ),
                 'innerBlocks' => array ( ),
                 'innerHTML' => '',
                 'innerContent' => array ( ),
         ),
 )
 */
 }}}

 However, this doesn't change anything in the editor. What is the expected
 behavior? Shouldn’t it override the navigation block’s links? It does
 nothing on my side.

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


More information about the wp-trac mailing list