#60846 closed defect (bug) (fixed)
When creating a new template, the Choose a pattern screen doesn't honor the `template_hierarchy` filter
Reported by: | aljullu | Owned by: | jorgefilipecosta |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | Editor | Keywords: | has-patch has-unit-tests |
Focuses: | template | Cc: |
Description
Currently, in blocks themes it's possible to use the ${type}_template_hierarchy
filter to alter the template hierarchy. However, those filters are not taken into consideration by the Choose a pattern
popup screen that appears when creating a new template in the Site Editor, causing a mismatch between the editor and the frontend.
Steps to reproduce
- Add this code snippet to your site. You can use the Code Snippets plugin:
<?php add_filter( 'page_template_hierarchy', function ( $templates ) { return ['single']; } );
- Visit any page in the frontend. You will notice the Single template is used, instead of the Page template.
- Now, go to Appearance > Editor > Templates > Add New Template > Pages and select any page.
- Notice in the Choose a pattern screen the suggested content to start with is from the Page template, instead of the Single template.
Expected result: the Site Editor should follow the filter in the same way the frontend does. So in step 4 the Single template should appear in the Choose a pattern screen, instead of the Page template.
Actual result screenshot
Expected result screenshot
Real life use case
In WooCommerce, there are Product Category and Product Tag templates. Currently, they fall back to the default WordPress taxonomy templates, but we would like them to fall back to a custom WooCommerce template named Product Catalog.
While this would work in the frontend, the experience would be confusing in the editor, as creating a Product Category archive template wouldn't suggest the same "starting point" from what's seen in the frontend.
Change History (11)
This ticket was mentioned in PR #6322 on WordPress/wordpress-develop by @aljullu.
6 months ago
#1
- Keywords has-patch has-unit-tests added
6 months ago
#2
cc @gziolo in case you have some thoughts on the issue and the approach taken in this PR.
Also cc @ntsekouras as I think you wrote most of the code this PR is based on here: https://github.com/WordPress/gutenberg/pull/42520.
Thanks in advance, folks!
#3
@
6 months ago
- Milestone changed from Awaiting Review to Future Release
- Version changed from trunk to 6.1
This was added in GB13.9 which was a part of 6.1, so adjusting the version accodingly
6 months ago
#4
Also cc @ntsekouras as I think you wrote most of the code this PR is based on here: https://github.com/WordPress/gutenberg/pull/42520.
Nik might have better insights as he worked on the code.
6 months ago
#5
Thanks for taking a look, folks! I updated the PR based on the provided feedback.
I'm wondering though why not start with a PR in Gutenberg repo. This issue it seems will be included in 6.6 and is needed in GB too.
I'm probably missing something from how the Gutenberg → WordPress code transfer works. While I know these functions were first introduced in Gutenberg, I thought they were moved to WordPress core and new contributions/updates should be done here? Or is there another way of approaching this?
---
Note: some PHP tests are failing, but it doesn't seem related to this PR and they are failing in other PRs too.
@ntsekouras commented on PR #6322:
6 months ago
#6
but testing the function on Gutenberg plugin is not trivial as it is not there anymore. I will look into hot to reverse port this PR to Gutenberg and propose a solution today.
Thanks for looking here @jorgefilipecosta and for looking for the GB PR. I think we need to override just one class function that uses this one.
5 months ago
#7
@jorgefilipecosta thanks for bringing this change to Gutenberg! Now that this has been merged there, should I close this PR and the associated trac ticket?
This ticket was mentioned in PR #6370 on WordPress/wordpress-develop by @jorgefilipecosta.
5 months ago
#8
Copy of https://github.com/WordPress/wordpress-develop/pull/6322 just to execute the CI after a rebase.
#9
@
5 months ago
- Owner set to jorgefilipecosta
- Resolution set to fixed
- Status changed from new to closed
In 57944:
@jorgefilipecosta commented on PR #6322:
5 months ago
#10
@jorgefilipecosta thanks for bringing this change to Gutenberg! Now that this has been merged there, should I close this PR and the associated trac ticket?
Yes, I'm closing this PR as it was committed to both Gutenberg and core trunk at https://github.com/WordPress/wordpress-develop/commit/f18c917f6d9aee873513ab8ae531d670a865e638.
## Testing steps
{{{PHP
add_filter( 'page_template_hierarchy', function ( $templates ) {
} );
}}}
Before | After
--- | ---
Trac ticket: https://core.trac.wordpress.org/ticket/60846