Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#51644 new defect (bug)

allowed_block_types breaks if array keys become non-sequential

Reported by: gyrus's profile gyrus Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.5.1
Component: Editor Keywords:
Focuses: Cc:


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

Change History (1)

This ticket was mentioned in Slack in #core-editor by skorasaurus. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.