Make WordPress Core

Opened 6 months ago

Closed 4 months ago

Last modified 4 months ago

#61804 closed feature request (fixed)

Create a plugin template registration API

Reported by: aljullu's profile aljullu Owned by: noisysocks's profile noisysocks
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.7
Component: Editor Keywords: has-patch has-unit-tests
Focuses: template, rest-api Cc:

Description

This ticket is the counterpart of https://github.com/WordPress/gutenberg/issues/41401 in WP core, so we can create the backport PR.

The goal is to create an API that allows plugins to easily register block templates so they can be used in the Site Editor and can be hooked into the frontend rendering logic.

Change History (16)

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


6 months ago
#1

  • Keywords has-patch has-unit-tests added

This PR includes the changes that need to be backported from https://github.com/WordPress/gutenberg/pull/61577 into WC core.

Trac ticket: https://core.trac.wordpress.org/ticket/61804

@aljullu commented on PR #7125:


6 months ago
#2

@youknowriad I've tested the PHP APIs in this PR and they are working as expected. Unfortunately, I didn't find a way to reproduce all the testing steps from https://github.com/WordPress/gutenberg/pull/61577. This PR doesn't include the JS changes from the original PR so template revert/removal doesn't work. Is it expected that this kind of PRs can't be tested right away, or am I missing something?

@youknowriad commented on PR #7125:


5 months ago
#3

@Aljullu yes, that's fine, it means this PR can only be merged after the package update on Core.

@aljullu commented on PR #7125:


5 months ago
#4

Thanks for the review @peterwilsoncc! I have applied all your feedback.

@noisysocks commented on PR #7125:


4 months ago
#5

Although this needs a little work before landing in the final release, I am a little tempted to merge the code in it's current form while performance is figured out so we can merge in the inital package update. What do you think @azaozz @noisysocks?

If there's no outstanding blocking comments I'm ok with this.

@antonvlasenko commented on PR #7125:


4 months ago
#6

Although this needs a little work before landing in the final release, I am a little tempted to merge the code in it's current form while performance is figured out so we can merge in the inital package update. What do you think @azaozz @noisysocks?

If there's no outstanding blocking comments I'm ok with this.

@noisysocks Speaking of blocking comments, the code currently has some compatibility issues with PHP 8.2, as it introduces a dynamic property (WP_Block_Template::$plugin).
I also have concerns regarding https://github.com/WordPress/wordpress-develop/pull/7125#discussion_r1742133430 (might not work as expected).
In my opinion, this PR may not be ready to be merged in its current state.

@aljullu commented on PR #7125:


4 months ago
#7

Thanks for the review @anton-vlasenko! I have addressed all your feedback, I would appreciate it if you can take another look.

There is also this open discussion about finding a more performant way to retrieve the plugin author text, but I might need some assistance on how to proceed. Also I don't know if it's a blocker.

@azaozz commented on PR #7125:


4 months ago
#8

Although this needs a little work before landing in the final release, I am a little tempted to merge the code in it's current form while performance is figured out

Sounds good to me too after all of @anton-vlasenko's suggestions and fixes were added. Would be nice to address/fix the performance improvements from above but as that affect only the site editor don't think it is a blocker.

@peterwilsoncc commented on PR #7125:


4 months ago
#9

I've merged trunk in and renamed a class in the tests folder (ie, it won't effect your source code). If @anton-vlasenko is happy with the change a few hours ago then I think it's good to go.

@antonvlasenko commented on PR #7125:


4 months ago
#10

I've merged trunk in and renamed a class in the tests folder (ie, it won't effect your source code). If @anton-vlasenko is happy with the change a few hours ago then I think it's good to go.

@peterwilsoncc I don't see any blockers at the moment. Thanks!

#11 @peterwilsoncc
4 months ago

  • Component changed from General to Editor
  • Focuses rest-api added
  • Milestone changed from Awaiting Review to 6.7

@peterwilsoncc commented on PR #7125:


4 months ago
#12

I've merged in trunk and pushed a couple of test nitpicks in e8b2b2c1fa4047d0df2e1d4be624d3814fb971ff and some docs standards fixes in 9a18a250fe89552522188e2d9e2a254cf7e9dd1a

@peterwilsoncc commented on PR #7125:


4 months ago
#13

I think this is good to go in, @noisysocks are you able to take a look to make sure I am not missing something obvious that will effect the editor?

@noisysocks commented on PR #7125:


4 months ago
#14

Looks OK to me. We'll have to wait until packages are synced before we commit.

#15 @noisysocks
4 months ago

  • Owner set to noisysocks
  • Resolution set to fixed
  • Status changed from new to closed

In 59073:

Editor: Add plugin template registration API and improve theme overrides for plugin-registered templates

This commit introduces a new API to allow plugins to easily register block
templates with wp_register_block_template() and the
WP_Block_Templates_Registry class, addressing the complexity of hooking into
multiple filters. It also ensures plugin-registered templates overridden by
themes fall back to the plugin-provided title and description when the theme
doesn't define them.

See https://github.com/WordPress/gutenberg/pull/61577.
See https://github.com/WordPress/gutenberg/pull/64610.

Fixes #61804.
Props aljullu, peterwilsoncc, antonvlasenko, azaozz, youknowriad, noisysocks.

@noisysocks commented on PR #7125:


4 months ago
#16

Committed in r59073..

Note: See TracTickets for help on using tickets.