Fix overriding `archive-product` when saving a fallback template (https://github.com/woocommerce/woocommerce-blocks/pull/7975)
* Fix overriding archive-product when saving a fallback template * Add comment
This commit is contained in:
parent
7dfced254a
commit
5b095eb1a2
|
@ -93,12 +93,11 @@ class BlockTemplatesController {
|
|||
}
|
||||
|
||||
$wp_query_args = array(
|
||||
'post_name__in' => array( 'archive-product' ),
|
||||
'post_type' => $template_type,
|
||||
'post_status' => array( 'auto-draft', 'draft', 'publish', 'trash' ),
|
||||
'posts_per_page' => 1,
|
||||
'no_found_rows' => true,
|
||||
'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
|
||||
'post_name__in' => array( 'archive-product', $slug ),
|
||||
'post_type' => $template_type,
|
||||
'post_status' => array( 'auto-draft', 'draft', 'publish', 'trash' ),
|
||||
'no_found_rows' => true,
|
||||
'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
|
||||
array(
|
||||
'taxonomy' => 'wp_theme',
|
||||
'field' => 'name',
|
||||
|
@ -109,6 +108,12 @@ class BlockTemplatesController {
|
|||
$template_query = new \WP_Query( $wp_query_args );
|
||||
$posts = $template_query->posts;
|
||||
|
||||
// If we have more than one result from the query, it means that the current template is present in the db (has
|
||||
// been customized by the user) and we should not return the `archive-product` template.
|
||||
if ( count( $posts ) > 1 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( count( $posts ) > 0 ) {
|
||||
$template = _build_block_template_result_from_post( $posts[0] );
|
||||
|
||||
|
@ -117,6 +122,7 @@ class BlockTemplatesController {
|
|||
$template->slug = $slug;
|
||||
$template->title = BlockTemplateUtils::get_block_template_title( $slug );
|
||||
$template->description = BlockTemplateUtils::get_block_template_description( $slug );
|
||||
unset( $template->source );
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue