From 9df1424d88cf415c5d12adb05f8ca93545b4d20f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 26 Aug 2016 21:02:08 +0000 Subject: [PATCH] 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 --- src/wp-includes/template.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index 380bb47b39..e7de9def9b 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -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 *