Make WordPress Core

Opened 8 months ago

Last modified 3 months ago

#56865 reviewing defect (bug)

$args taking effect too late in register_block_type_from_metadata

Reported by: aristath's profile aristath Owned by: audrasjb's profile audrasjb
Milestone: 6.3 Priority: normal
Severity: normal Version: 6.2
Component: General Keywords: has-patch needs-testing has-unit-tests
Focuses: Cc:

Description

The register_block_type_from_metadata function accepts 2 arguments:

  • $file_or_folder
  • $args

The $file_or_folder is a path the the block.json file, or the folder containing it. $args is an array of arguments that can be passed to the function in order to provide complimentary data.
The problem right now is that $args are parsed too late: They get parsed after the scripts/styles have been registered, after all other calculations have been completed, right before we call WP_Block_Type_Registry::get_instance()->register();.
The problem with the current approach is that $args are unable to register script/styles, or even be used to take part in all the processing that the register_block_type_from_metadata function does.
As a side-effect, it's impossible to register a block by passing an array of arguments, without the presence of a block.json file.

Change History (11)

This ticket was mentioned in PR #3501 on WordPress/wordpress-develop by @aristath.


8 months ago
#1

  • Keywords has-patch added

#2 @SergeyBiryukov
8 months ago

  • Milestone changed from Awaiting Review to 6.2

This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.


4 months ago

This ticket was mentioned in Slack in #core by costdev. View the logs.


3 months ago

#5 @audrasjb
3 months ago

  • Owner set to audrasjb
  • Status changed from new to reviewing

As per today's bug scrub, self assigning for review

This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.


3 months ago

#7 @mukesh27
3 months ago

  • Keywords needs-testing added

This ticket was discussed in the bug scrub.

THe PR need some manual testing.

Additional props @costdev

#8 @costdev
3 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from 6.2 to 6.3

The PR could also use a unit test to ensure that it's now possible to register a block by passing an array of arguments, without the presence of a block.json file, and is protected going forward.

As this still needs some work, I'm moving this to the 6.3 milestone. If testing and unit tests are ready before RC1, feel free to pull this ticket back into the 6.2 milestone for commit consideration.

@aristath commented on PR #3501:


3 months ago
#9

Added PHPUnit tests and fixed issues that surfaced from said tests.

This ticket was mentioned in Slack in #core by aristath. View the logs.


3 months ago

#11 @costdev
3 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed
Note: See TracTickets for help on using tickets.