Make WordPress Core

Changeset 15611


Ignore:
Timestamp:
09/12/2010 06:46:18 PM (14 years ago)
Author:
scribu
Message:

Apply filters consistently in get_*_template() functions. Fixes #14310

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r15590 r15611  
    688688
    689689/**
    690  * Retrieve path to file without the use of extension.
    691  *
    692  * Used to quickly retrieve the path of file without including the file
    693  * extension. It will also check the parent template, if the file exists, with
    694  * the use of {@link locate_template()}. Allows for more generic file location
     690 * Retrieve path to a template
     691 *
     692 * Used to quickly retrieve the path of a template without including the file
     693 * extension. It will also check the parent theme, if the file exists, with
     694 * the use of {@link locate_template()}. Allows for more generic template location
    695695 * without the use of the other get_*_template() functions.
    696696 *
    697  * Can be used with include() or require() to retrieve path.
    698  * <code>
    699  * if( '' != get_query_template( '404' ) )
    700  *     include( get_query_template( '404' ) );
    701  * </code>
    702  * or the same can be accomplished with
    703  * <code>
    704  * if( '' != get_404_template() )
    705  *     include( get_404_template() );
    706  * </code>
    707  *
    708697 * @since 1.5.0
    709698 *
    710699 * @param string $type Filename without extension.
     700 * @param array $templates An optional list of template candidates
    711701 * @return string Full path to file.
    712702 */
    713 function get_query_template($type) {
     703function get_query_template( $type, $templates = array() ) {
    714704    $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
    715     return apply_filters("{$type}_template", locate_template(array("{$type}.php")));
     705
     706    if ( empty( $templates ) )
     707        $templates = array("{$type}.php");
     708
     709    $templates = apply_filters( "{$type}_template_hierarchy", $templates );
     710
     711    return apply_filters( "{$type}_template", locate_template( $templates ) );
    716712}
    717713
     
    769765    $templates[] = 'author.php';
    770766
    771     $template = locate_template( $templates );
    772     return apply_filters( 'author_template', $template );
     767    return get_query_template( 'author', $templates );
    773768}
    774769
     
    791786    $templates = array();
    792787
    793     if ( !is_wp_error($category) )
     788    if ( !is_wp_error( $category ) )
    794789        $templates[] = "category-{$category->slug}.php";
    795790
     
    797792    $templates[] = "category.php";
    798793
    799     $template = locate_template($templates);
    800     return apply_filters('category_template', $template);
     794    return get_query_template( 'category', $templates );
    801795}
    802796
     
    825819    $templates[] = "tag.php";
    826820
    827     $template = locate_template($templates);
    828     return apply_filters('tag_template', $template);
     821    return get_query_template( 'tag', $templates );
    829822}
    830823
     
    858851    $templates[] = "taxonomy.php";
    859852
    860     $template = locate_template($templates);
    861     return apply_filters('taxonomy_template', $template);
     853    return get_query_template( 'taxonomy', $templates );
    862854}
    863855
     
    886878 */
    887879function get_home_template() {
    888     $template = locate_template(array('home.php', 'index.php'));
    889     return apply_filters('home_template', $template);
     880    $templates = array( 'home.php', 'index.php' );
     881
     882    return get_query_template( 'home', $templates );
    890883}
    891884
     
    901894 */
    902895function get_front_page_template() {
    903     return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) );
     896    $templates = array('front-page.php');
     897
     898    return get_query_template( 'front_page', $templates );
    904899}
    905900
     
    940935    $templates[] = "page.php";
    941936
    942     return apply_filters('page_template', locate_template($templates));
     937    return get_query_template( 'page', $templates );
    943938}
    944939
     
    977972    $object = $wp_query->get_queried_object();
    978973    $templates = array('single-' . $object->post_type . '.php', 'single.php');
    979     return apply_filters('single_template', locate_template($templates));
     974
     975    return get_query_template( 'single', $templates );
    980976}
    981977
     
    10201016 */
    10211017function get_comments_popup_template() {
    1022     $template = locate_template(array("comments-popup.php"));
     1018    $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
    10231019
    10241020    // Backward compat code will be removed in a future release
     
    10261022        $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
    10271023
    1028     return apply_filters('comments_popup_template', $template);
     1024    return $template;
    10291025}
    10301026
Note: See TracChangeset for help on using the changeset viewer.