[wp-trac] [WordPress Trac] #51644: allowed_block_types breaks if array keys become non-sequential

WordPress Trac noreply at wordpress.org
Tue Oct 27 12:40:22 UTC 2020


#51644: allowed_block_types breaks if array keys become non-sequential
--------------------------+-----------------------------
 Reporter:  gyrus         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  5.5.1
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When the blocks array is filtered using `allowed_block_types`, I want to
 remove some blocks.

 Using a loop and a combination of `array_search()` and `unset()`, I remove
 the blocks I need to remove.

 However, it seems that this results in all blocks being available (the
 same as returning true for `allowed_block_types`).

 This can be easily averted in your own hooked function by using `$blocks =
 array_values( $blocks )` to reset the array keys so they're sequential
 again.

 However, this seems like a minor bug worth fixing at root for anyone else
 removing blocks this way (apply `array_values()` to the array if an array
 is returned by the `allowed_block_types` filter).

 Not sure if this might be affected by decisions made for
 https://core.trac.wordpress.org/ticket/50706

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51644>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list