WordPress / WordPress/create-block-theme
Saving theme creates unnecessary patterns
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 417
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
I encountered this problem working with the plugin version 2.0.2 and WooCommerce templates, but it may be more widespread.
What happens?
Originally, the taxonomy-product_cat.html template contains this snippet:
<!-- wp:query-no-results -->
<!-- wp:pattern {"slug":"woocommerce/no-products-found"} /-->
<!-- /wp:query-no-results -->
In the editor the pattern is visible as a paragraph block telling "No products were found matching your selection."
When I modify the template and save the theme to files, the whole template gets replaced with:
<!-- wp:pattern {"slug":"mytheme/taxonomy-product_cat"} /-->
and a new pattern is created in patterns/taxonomy-product_cat.php
This pattern contains:
<!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p><?php echo __('No products were found matching your selection.', 'mytheme');?></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
I also tried with a custom pattern:
/**
* Title: no-products-found
* Slug: mytheme/no-products-found
* Categories: hidden
* Inserter: no
*/
?>
<!-- wp:paragraph -->
<p><?php echo __('No products were found matching your selection.', 'mytheme');?></p>
<!-- /wp:paragraph -->
and it behaves the same as the WooCommerce one.
What should happen?
As I already have <!-- wp:pattern {"slug":"woocommerce/no-products-found"} /--> (or my custom pattern) which is dynamically translated, I want to keep it in a regular template taxonomy-product_cat.html after saving without getting that mostly redundant taxonomy-product_cat.php created.
May be related to
#533 Export creates new patterns by copying content from other patterns, without re-using them
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the save-theme-to-files export path in the create-block-theme plugin and compare how taxonomy-product_cat.html handles the wp:pattern reference. Done means saving preserves the existing pattern reference in the template and does not create the redundant patterns/taxonomy-product_cat.php file; issue #533 may provide related context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, javascript, php
- Domain
- content, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100