Make WordPress Core

Opened 2 years ago

Closed 8 months ago

Last modified 4 months ago

#55319 closed enhancement (reported-upstream)

Add filter to get_block_wrapper_attributes function

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

Description

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: https://github.com/WordPress/WordPress/blob/92f0b0cb48a3de660655cc658fc739695a393096/wp-includes/class-wp-block-supports.php#L93-L128

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(https://github.com/WordPress/gutenberg/issues/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 (3)

#1 @fabiankaegy
2 years ago

This ticket and how it should be approached was discussed in slack here: https://wordpress.slack.com/archives/C02QB2JS7/p1646070868485339

#2 @fabiankaegy
8 months ago

  • Resolution set to reported-upstream
  • Status changed from new to closed

This ticket was discussed in GitHub and got resolved there https://github.com/WordPress/gutenberg/issues/38830

#3 @swissspidy
4 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.