-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Honor 'template_hierarchy' filters when creating a template in the Site Editor #6322
Honor 'template_hierarchy' filters when creating a template in the Site Editor #6322
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
379772f
to
82149d6
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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: WordPress/gutenberg#42520. Thanks in advance, folks! |
} | ||
$valid_template_types = array( '404', 'archive', 'attachment', 'author', 'category', 'date', 'embed', 'frontpage', 'home', 'index', 'page', 'paged', 'privacypolicy', 'search', 'single', 'singular', 'tag', 'taxonomy' ); | ||
if ( in_array( $template_type, $valid_template_types ) ) { | ||
return apply_filters( "{$template_type}_template_hierarchy", $template_hierarchy ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The document is missing for filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nik might have better insights as he worked on the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @Aljullu! In general I think it's a fine addition to apply the filter. 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.
} else { | ||
list( $template_type ) = explode( '-', $slug ); | ||
} | ||
$valid_template_types = array( '404', 'archive', 'attachment', 'author', 'category', 'date', 'embed', 'frontpage', 'home', 'index', 'page', 'paged', 'privacypolicy', 'search', 'single', 'singular', 'tag', 'taxonomy' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you got these from: https://developer.wordpress.org/reference/hooks/type_template_hierarchy/, right?
The logic for checking whether to apply the filter or not, I guess could go on top of the function, since we already have some early returns.
Regarding the actual logic for template_type, I'd love some eyes from @jorgefilipecosta, since while I introduced this function, he has updated it afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you got these from: https://developer.wordpress.org/reference/hooks/type_template_hierarchy/, right?
Yup, directly from the documented code, in fact:
https://github.com/WordPress/wordpress-develop/blob/6.4/src/wp-includes/template.php#L39-L56
The logic for checking whether to apply the filter or not, I guess could go on top of the function, since we already have some early returns.
Good catch, I missed those early returns. In c83b3ac I updated the code so we call apply_filter()
on those early returns as well. It's not 100% clear to me if that's what you were proposing or you have a better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was it, thank you! We just need a quick look from @jorgefilipecosta now :)
74251ec
to
a9065d5
Compare
a9065d5
to
c83b3ac
Compare
Thanks for taking a look, folks! I updated the PR based on the provided feedback.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good 👍 Thank you @Aljullu for working on this. I think this PR can be added to core. It deserves some testing on the Gutenberg plugin, 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. |
@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, This PR can be closed as it was committed to both Gutenberg and core trunk at f18c917. |
Testing steps
Trac ticket: https://core.trac.wordpress.org/ticket/60846
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.