Make WordPress Core

Opened 15 months ago

Last modified 15 months ago

#55319 new enhancement

Add filter to get_block_wrapper_attributes function

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


What problem does this address?

It is currently possible to add custom classnames to static blocks using the blocks.getSaveContent.extraProps filter in JS. This is super useful when working with custom block supports. And even core uses this system in js to add the classnames generated for for example the color classes.

In PHP however, for custom blocks this is all hardcoded in the get_block_wrapper_attributes function. Specifically inside the WP_Block_Supports Class here:

This approach makes it impossible for custom supports that plugins develop to apply to custom blocks.

What is your proposed solution?

This could be solved by adding a new hook in PHP to the get_block_wrapper_attributes function which should work the same as the
blocks.getSaveContent.extraProps hook in js.

This ticket was first created in GitHub on the Gutenberg repository in #38830( but as the code no longer exists in Gutenberg since it was moved to core in 5.8 it was suggested that the change needs to happen in core directly.

Change History (1)

#1 @fabiankaegy
15 months ago

This ticket and how it should be approached was discussed in slack here:

Note: See TracTickets for help on using tickets.