Make WordPress Core

Ticket #12877: 12877.patch

File 12877.patch, 4.0 KB (added by scribu, 14 years ago)

refresh

  • wp-includes/template-loader.php

     
    1818        return;
    1919endif;
    2020
     21/**
     22 * Locates and loads the template for current page ($wp_query).
     23 *
     24 * @since 3.1.0
     25 */
     26function template_loader() {
    2127if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
    2228        $template = false;
    2329        if     ( is_404()            && $template = get_404_template()            ) :
     
    4349                include( $template );
    4450        return;
    4551endif;
     52}
    4653
     54update_template_hierarchy();
     55template_loader();
     56
    4757?>
  • wp-includes/theme.php

     
    10421042 * @return string The template filename if one is located.
    10431043 */
    10441044function locate_template($template_names, $load = false, $require_once = true ) {
     1045        $template_names = apply_filters('locate_template', $template_names);
     1046
    10451047        if ( !is_array($template_names) )
    10461048                return '';
    10471049
     
    10891091}
    10901092
    10911093/**
     1094 * Creates a global variable that contains the template hierarchy for the current page.
     1095 *
     1096 * Calling update_template_hierarchy() will recalculate the template hierarchy for $wp_query.
     1097 *
     1098 * @uses template_loader() Calculates the template hierarchy.
     1099 * @since 3.1.0
     1100 */
     1101function update_template_hierarchy() {
     1102        global $wp_template_hierarchy;
     1103       
     1104        add_filter('locate_template', '_record_template_hierarchy');
     1105        add_filter('template_include', '__return_false');
     1106        $wp_template_hierarchy = array();
     1107        template_loader();
     1108        remove_filter('locate_template', '_record_template_hierarchy');
     1109        remove_filter('template_include', '__return_false');
     1110        $wp_template_hierarchy = call_user_func_array('array_merge', $wp_template_hierarchy);
     1111}
     1112
     1113/**
     1114 * Returns the template hierarchy for the current page.
     1115 *
     1116 * @since 3.1.0
     1117 *
     1118 * @return array
     1119 */
     1120function get_template_hierarchy() {
     1121        global $wp_template_hierarchy;
     1122        return $wp_template_hierarchy;
     1123}
     1124
     1125/**
     1126 * Private function to modify locate_template() when updating the
     1127 * template hierarchy.
     1128 *
     1129 * Records $template_names in $wp_template_hierarchy, then returns false
     1130 * which causes locate_template() to fail.
     1131 *
     1132 * @since 3.1.0
     1133 * @access private
     1134 *
     1135 * @param array $template_names Template files to look for in locate_template.
     1136 * @return array
     1137 */
     1138function _record_template_hierarchy( $template_names ) {
     1139        global $wp_template_hierarchy;
     1140        $wp_template_hierarchy[] = $template_names;
     1141        return false;
     1142}
     1143
     1144/**
    10921145 * Display localized stylesheet link element.
    10931146 *
    10941147 * @since 2.1.0
  • wp-includes/general-template.php

     
    129129}
    130130
    131131/**
     132 * Load a template from a folder based upon the best match from the template hierarchy.
     133 *
     134 * Makes it easy for a theme to reuse sections of code in a easy to overload way
     135 * for child themes.
     136 *
     137 * Includes a template from a folder within a theme based upon the most specific
     138 * match from the template hierarchy. If the folder contains no matching files
     139 * then no template will be included.
     140 *
     141 * @uses get_template_hierarchy() To build template file names.
     142 * @uses locate_template() To search for template files.
     143 * @since 3.1.0
     144 *
     145 * @param string $folder The name of the folder to be searched.
     146 * @return string The file path to the loaded file. The empty string if no file was found.
     147 */
     148function get_template_module( $folder ) {
     149        $template_hierarchy = get_template_hierarchy();
     150        $template_names = array();
     151        foreach( $template_hierarchy as $template_name ) {
     152                $template_names[] = $folder . '/' . $template_name;
     153        }
     154        $located = locate_template($template_names);
     155        if( $located )
     156                include( $located );
     157        return $located;
     158}
     159
     160/**
    132161 * Display search form.
    133162 *
    134163 * Will first attempt to locate the searchform.php file in either the child or