Skip to content
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

Make plugin-registered templates overriden by themes to fall back to plugin-registered title and description #64610

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backport-changelog/6.7/7125.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/7125

* https://github.com/WordPress/gutenberg/pull/61577
* https://github.com/WordPress/gutenberg/pull/64610
14 changes: 10 additions & 4 deletions lib/compat/wordpress-6.7/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ function _gutenberg_add_block_templates_from_registry( $query_result, $query, $t
foreach ( $query_result as $key => $value ) {
$registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $query_result[ $key ]->slug );
if ( $registered_template ) {
$query_result[ $key ]->plugin = $registered_template->plugin;
$query_result[ $key ]->origin =
$query_result[ $key ]->plugin = $registered_template->plugin;
$query_result[ $key ]->origin =
'theme' !== $query_result[ $key ]->origin && 'theme' !== $query_result[ $key ]->source ?
'plugin' :
$query_result[ $key ]->origin;
$query_result[ $key ]->title =
empty( $query_result[ $key ]->title ) || $query_result[ $key ]->title === $query_result[ $key ]->slug ?
$registered_template->title : $query_result[ $key ]->title;
$query_result[ $key ]->description = empty( $query_result[ $key ]->description ) ? $registered_template->description : $query_result[ $key ]->description;
}
}

Expand Down Expand Up @@ -70,11 +74,13 @@ function _gutenberg_add_block_template_plugin_attribute( $block_template ) {
if ( $block_template ) {
$registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $block_template->slug );
if ( $registered_template ) {
$block_template->plugin = $registered_template->plugin;
$block_template->origin =
$block_template->plugin = $registered_template->plugin;
$block_template->origin =
'theme' !== $block_template->origin && 'theme' !== $block_template->source ?
'plugin' :
$block_template->origin;
$block_template->title = empty( $block_template->title ) || $block_template->title === $block_template->slug ? $registered_template->title : $block_template->title;
$block_template->description = empty( $block_template->description ) ? $registered_template->description : $block_template->description;
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/specs/site-editor/template-registration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ test.describe( 'Block template registration', () => {
await expect(
page.getByText( 'Custom Template (overridden by the theme)' )
).toBeHidden();
// Verify the template description fall backs to the plugin registered description.
await expect(
page.getByText(
'A custom template registered by a plugin and overridden by a theme.'
)
).toBeVisible();
// Verify the theme template shows the theme name as the author.
await expect( page.getByText( 'AuthorEmptytheme' ) ).toBeVisible();
} );
Expand Down
Loading