From bae3fb43a524faeeed6eb2aeacb628cf4108067c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 7 Mar 2016 19:33:01 +0000 Subject: [PATCH] Embeds: Add support for embeds in the theme template hierarchy. This allows themes to directly override the default template. The order in which the template is retrieved is as follows: `embed-$post_type-$post_format.php` -> `embed-$post_type.php` -> `embed.php`. The `embed_template` filter gets replaced by the dynamic `{$type}_template` filter in `get_query_template()`. Props ChriCo, swissspidy. See #34561. Fixes #34278. git-svn-id: https://develop.svn.wordpress.org/trunk@36876 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/template-loader.php | 18 ++--------------- src/wp-includes/template.php | 31 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/template-loader.php b/src/wp-includes/template-loader.php index 30626c8868..68c66b198b 100644 --- a/src/wp-includes/template-loader.php +++ b/src/wp-includes/template-loader.php @@ -39,26 +39,12 @@ elseif ( is_feed() ) : elseif ( is_trackback() ) : include( ABSPATH . 'wp-trackback.php' ); return; -elseif ( is_embed() ) : - $template = ABSPATH . WPINC . '/theme-compat/embed.php'; - - /** - * Filter the template used for embedded posts. - * - * @since 4.4.0 - * @since 4.5.0 The default template path changed to wp-includes/theme-compat/embed.php - * - * @param string $template Path to the template file. - */ - $template = apply_filters( 'embed_template', $template ); - - include ( $template ); - return; endif; if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) : $template = false; - if ( is_404() && $template = get_404_template() ) : + if ( is_embed() && $template = get_embed_template() ) : + elseif ( is_404() && $template = get_404_template() ) : elseif ( is_search() && $template = get_search_template() ) : elseif ( is_front_page() && $template = get_front_page_template() ) : elseif ( is_home() && $template = get_home_template() ) : diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index 315f2e8d2a..032243a289 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -404,6 +404,37 @@ function get_single_template() { return get_query_template( 'single', $templates ); } +/** + * Retrieve path of embed template in current or parent template. + * By default the WordPress-template is returned. + * + * The template path is filterable via the dynamic {@see '$type_template'} hook, + * e.g. 'embed_template'. + * + * @since 4.5.0 + * + * @see get_query_template() + * + * @return string Full path to embed template file. + */ +function get_embed_template() { + $object = get_queried_object(); + + $templates = array(); + + if ( ! empty( $object->post_type ) ) { + $post_format = get_post_format( $object ); + if ( $post_format ) { + $templates[] = "embed-{$object->post_type}-{$post_format}.php"; + } + $templates[] = "embed-{$object->post_type}.php"; + } + + $templates[] = "embed.php"; + + return get_query_template( 'embed', $templates ); +} + /** * Retrieves the path of the singular template in current or parent template. *