-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use core version of template and template part post types and REST endpoints for WP 5.9, with back compat for 5.8 #36898
Conversation
Is it possible to move this code into |
@Mamaduka pointed out that this won't work for users of WordPress 5.8, because it'll cause Gutenberg to use the outdated REST APIs in 5.8.
@youknowriad Will that solve the problem mentioned above? I'll have a look at it. At the end of my day now, but I don't think there's a rush to do this, so will try to tackle it on Monday. |
No it won't but we can still achieve it by testing something specific to WP 5.9 before registering the CPT and endpoints. |
Great, thanks for the advice. I'll make those changes on Monday 👍 |
…WP5.8.x is active
…ives improvements to it
b03d527
to
b48f643
Compare
|
||
return $new_content; | ||
if ( ! $has_updated_content ) { | ||
return $template_content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were some minor changes to this function in WordPress core, so I've replicated them for Gutenberg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this branch there is no foreach ( $template_blocks as $block )
which is something I see in the Core version. Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, oops. I obviously wasn't thorough enough. Fixed in #37137.
@@ -9,7 +9,7 @@ | |||
/** | |||
* Class representing a block template. | |||
*/ | |||
class WP_Block_Template { | |||
class Gutenberg_Block_Template { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed this and the situation should be:
- If Gutenberg is running on WordPress 5.8,
Gutenberg_Block_Template
is used instead of WP_Block_Template`, since the latter is outdated in 5.8. - If Gutenberg is running on WordPress 5.9,
WP_Block_Template
is used.
This should resolve any issues where author
or origin
might not be defined on 5.8.
@@ -33,7 +33,6 @@ public function set_up() { | |||
* @param WP_UnitTest_Factory $factory Helper that lets us create fake data. | |||
*/ | |||
public static function wpSetupBeforeClass( $factory ) { | |||
gutenberg_register_wp_theme_taxonomy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is now not defined for Gutenberg running against WP 5.9, as the taxonomy is registered in core. The call here was making the test fail though. I deleted it and the tests still pass, so I'll call that a win 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Technically there's no backport to be done into Core but we should sync the "wp/trunk" branch, so I added the label. |
Thanks for the thumbs up. I'll do some testing against 5.8 tomorrow before merging just to make sure I didn't break anything. I'll also follow up to fix some more little inconsistencies between core and Gutenberg. |
Tested against 5.8.2 and can't see any issues, so moving ahead with merging this. |
…dpoints for WP 5.9, with back compat for 5.8 (#36898) * Use core version of template and template part post types and REST endpoints * Move files and add explanation * Only register gutenberg version of templates and template parts when WP5.8.x is active * Rename WP_Block_Template to Gutenberg_Block_Template so that 5.8 receives improvements to it * Load moved files * Update references and sync some code * Fix filename * Remove templates tests since Gutenberg now defaults to using the WP core implementation * Linting and test fixes
|
||
return $new_content; | ||
if ( ! $has_updated_content ) { | ||
return $template_content; | ||
} | ||
|
||
return $template_content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
is now unnecessary. In both cases we return $template_content;
. Is that right?
Description
When the Gutenberg plugin is active, it's currently using it's own version of the template and template part post types and REST endpoints.
Usually the practice is to rely on the core version of PHP code when it exists.
register_post_type
overwrites any previous registration and we don't want it to overwrite the core version of the post types. The fix here is to check whether the post types have already been registered before attempting to register them again.This also solves the REST API issue, as that's also defined as part of the post type configuration.
How has this been tested?
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).