Skip to content

Commit

Permalink
Fix issue with wrong author shown in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed May 13, 2024
1 parent 3d372fe commit 2fa0a91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/compat/wordpress-6.6/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ function _gutenberg_get_block_templates_files( $template_type, $query = array()
return array_values( $template_files );
}

function _gutenberg_add_template_details_from_registration( $template_type, $template_object_from_file ) {
$registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $template_type, $template_object_from_file->slug );
if ( $registered_template ) {
$template_object_from_file->plugin = $registered_template->plugin;
}
return $template_object_from_file;
}

/**
* Retrieves a list of unified template objects based on a query.
*
Expand Down Expand Up @@ -327,18 +335,21 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t
continue;
}

$query_result[] = $template;
$query_result[] = _gutenberg_add_template_details_from_registration( $template_type, $template );
}

if ( ! isset( $query['wp_id'] ) ) {

/*
* If the query has found some use templates, those have priority
* over the theme-provided ones, so we skip querying and building them.
*/
$query['slug__not_in'] = wp_list_pluck( $query_result, 'slug' );
$template_files = _gutenberg_get_block_templates_files( $template_type, $query );
foreach ( $template_files as $template_file ) {
$query_result[] = _build_block_template_result_from_file( $template_file, $template_type );
$template_object_from_file = _build_block_template_result_from_file( $template_file, $template_type );

$query_result[] = _gutenberg_add_template_details_from_registration( $template_type, $template_object_from_file );
}

/*
Expand Down Expand Up @@ -441,6 +452,8 @@ function gutenberg_get_block_template( $id, $template_type = 'wp_template' ) {
$block_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $template_type, $slug );
}

$block_template = _gutenberg_add_template_details_from_registration( $template_type, $block_template );

/**
* Filters the queried block template object after it's been fetched.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function get_template_fallback( $request ) {
public function get_item( $request ) {
if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
$template = get_block_file_template( $request['id'], $this->post_type );
$template = _gutenberg_add_template_details_from_registration( $this->post_type, $template );
} elseif ( isset( $request['source'] ) && 'plugin' === $request['source'] ) {
list( $namespace, $slug ) = explode( '//', $request['id'] );

Check warning on line 132 in lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Unused variable $namespace.
$template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $this->post_type, $slug );
Expand Down

0 comments on commit 2fa0a91

Please sign in to comment.