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

Built from https://develop.svn.wordpress.org/trunk@38385


git-svn-id: http://core.svn.wordpress.org/trunk@38326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2016-08-26 21:03:27 +00:00
parent 29959d0448
commit 9e1542b9ec
2 changed files with 16 additions and 2 deletions

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
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38384';
$wp_version = '4.7-alpha-38385';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.