Opened 5 years ago
Last modified 5 years ago
#51644 new defect (bug)
allowed_block_types breaks if array keys become non-sequential
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | minor | Version: | 5.5.1 |
| Component: | Editor | Keywords: | |
| Focuses: | Cc: |
Description
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