Opened 6 years ago
Last modified 6 years ago
#51644 new defect (bug)
allowed_block_types breaks if array keys become non-sequential
| Reported by: | gyrus | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | 5.5.1 |
| Severity: | minor | Keywords: | |
| Cc: | Focuses: |
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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)