Themes: Make the template hierarchy for a given template type filterable.

This introduces a `{$type}_template_hierarchy` filter that allows the hierarchy of candidate template filenames for a given template type to be filtered.

This allows the hierarchy to be added to or altered completely without resorting to re-building the hierarchy from scratch within the `template_include` filter, which is common and prone to conflicts between plugins and prone to getting out of sync with core's hierarchy.

Fixes #14310


git-svn-id: https://develop.svn.wordpress.org/trunk@38385 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2016-08-26 21:02:08 +00:00
parent 39a145e0e1
commit 9df1424d88

View File

@ -26,6 +26,20 @@ function get_query_template( $type, $templates = array() ) {
if ( empty( $templates ) )
$templates = array("{$type}.php");
/**
* Filter the list of template filenames that are searched for when retrieving a template to use.
*
* The last element in the array should always be the fallback template for this query type.
*
* Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
* 'embed', home', 'front_page', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
*
* @since 4.7.0
*
* @param array $templates A list of template candidates, in descending order of priority.
*/
$templates = apply_filters( "{$type}_template_hierarchy", $templates );
$template = locate_template( $templates );
/**
@ -36,7 +50,7 @@ function get_query_template( $type, $templates = array() ) {
* This hook also applies to various types of files loaded as part of the Template Hierarchy.
*
* Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
* 'home', 'front_page', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
* 'embed', home', 'front_page', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
*
* @since 1.5.0
*