Skip to content

Commit

Permalink
Make sure correct template author is displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Aug 13, 2024
1 parent de4ac59 commit 00d9f40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/compat/wordpress-6.7/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ function _gutenberg_add_block_templates_from_registry( $query_result, $query, $t
$registered_template = WP_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 = 'theme' !== $query_result[ $key ]->origin ? 'plugin' : $query_result[ $key ]->origin;
$query_result[ $key ]->origin =
'theme' !== $query_result[ $key ]->origin && 'theme' !== $query_result[ $key ]->source ?
'plugin' :
$query_result[ $key ]->origin;
}
}

Expand Down Expand Up @@ -68,7 +71,10 @@ function _gutenberg_add_block_template_plugin_attribute( $block_template ) {
$registered_template = WP_Templates_Registry::get_instance()->get_by_slug( $block_template->slug );
if ( $registered_template ) {
$block_template->plugin = $registered_template->plugin;
$block_template->origin = 'theme' !== $block_template->origin ? 'plugin' : $block_template->origin;
$block_template->origin =
'theme' !== $block_template->origin && 'theme' !== $block_template->source ?
'plugin' :
$block_template->origin;
}
}

Expand All @@ -88,7 +94,10 @@ function _gutenberg_add_block_file_templates_from_registry( $block_template, $id
$registered_template = WP_Templates_Registry::get_instance()->get_by_slug( $block_template->slug );
if ( $registered_template ) {
$block_template->plugin = $registered_template->plugin;
$block_template->origin = 'theme' !== $block_template->origin ? 'plugin' : $block_template->origin;
$block_template->origin =
'theme' !== $block_template->origin && 'theme' !== $block_template->source ?
'plugin' :
$block_template->origin;
}
return $block_template;
}
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/specs/site-editor/template-registration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ test.describe( 'Template registration', () => {
await admin.visitSiteEditor( {
postType: 'wp_template',
} );
await templateRegistrationUtils.searchForTemplate( 'Custom Template' );
await templateRegistrationUtils.searchForTemplate( 'Custom' );
await expect(
page.getByText( 'Custom Template (overridden by the theme)' )
).toBeHidden();
// Verify the theme template shows the theme name as the author.
await expect( page.getByText( 'AuthorEmptytheme' ) ).toBeVisible();
} );

test( 'templates can be deleted if the registered plugin is deactivated', async ( {
Expand Down

0 comments on commit 00d9f40

Please sign in to comment.