Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#61804 closed feature request (fixed)

Create a plugin template registration API

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

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.


2 years 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:


2 years 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:


2 years 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:


2 years ago
#4

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

​@noisysocks commented on ​PR #7125:


2 years 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:


2 years 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:


2 years 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:


2 years 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:


2 years 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:


2 years 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
2 years ago

  • Component General → Editor
  • Focuses rest-api added
  • Milestone Awaiting Review → 6.7

​@peterwilsoncc commented on ​PR #7125:


2 years 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:


2 years 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:


2 years ago
#14

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

#15 @noisysocks
2 years ago

  • Owner set to noisysocks
  • Resolution → fixed
  • Status new → 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:


2 years ago
#16

Committed in r59073..

Note: See TracTickets for help on using tickets.