Make WordPress Core

Ticket #12877: 12877.5.patch

File 12877.5.patch, 4.2 KB (added by scribu, 14 years ago)

Don't include() directly in get_template_module()

  • 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()            ) :
     
    4046                $template = get_index_template();
    4147        endif;
    4248        if ( $template = apply_filters( 'template_include', $template ) )
    43                 include( $template );
     49                load_template( $template );
    4450        return;
    4551endif;
     52}
    4653
     54update_template_hierarchy();
     55template_loader();
     56
    4757?>
  • wp-includes/theme.php

     
    10771077 * @return string The template filename if one is located.
    10781078 */
    10791079function locate_template($template_names, $load = false, $require_once = true ) {
     1080        $template_names = apply_filters( 'locate_template', $template_names );
     1081
    10801082        $located = '';
    10811083        foreach ( (array) $template_names as $template_name ) {
    10821084                if ( !$template_name )
     
    11211123}
    11221124
    11231125/**
     1126 * Creates a global variable that contains the template hierarchy for the current page.
     1127 *
     1128 * Calling update_template_hierarchy() will recalculate the template hierarchy for $wp_query.
     1129 *
     1130 * @uses template_loader() Calculates the template hierarchy.
     1131 * @since 3.1.0
     1132 */
     1133function update_template_hierarchy() {
     1134        global $wp_template_hierarchy;
     1135       
     1136        add_filter('locate_template', '_record_template_hierarchy');
     1137        add_filter('template_include', '__return_false');
     1138        $wp_template_hierarchy = array();
     1139        template_loader();
     1140        remove_filter('locate_template', '_record_template_hierarchy');
     1141        remove_filter('template_include', '__return_false');
     1142        $wp_template_hierarchy = call_user_func_array('array_merge', $wp_template_hierarchy);
     1143}
     1144
     1145/**
     1146 * Returns the template hierarchy for the current page.
     1147 *
     1148 * @since 3.1.0
     1149 *
     1150 * @return array
     1151 */
     1152function get_template_hierarchy() {
     1153        global $wp_template_hierarchy;
     1154        return $wp_template_hierarchy;
     1155}
     1156
     1157/**
     1158 * Private function to modify locate_template() when updating the
     1159 * template hierarchy.
     1160 *
     1161 * Records $template_names in $wp_template_hierarchy, then returns false
     1162 * which causes locate_template() to fail.
     1163 *
     1164 * @since 3.1.0
     1165 * @access private
     1166 *
     1167 * @param array $template_names Template files to look for in locate_template.
     1168 * @return array
     1169 */
     1170function _record_template_hierarchy( $template_names ) {
     1171        global $wp_template_hierarchy;
     1172        $wp_template_hierarchy[] = $template_names;
     1173        return false;
     1174}
     1175
     1176/**
    11241177 * Display localized stylesheet link element.
    11251178 *
    11261179 * @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
     155        return locate_template($template_names, true);
     156}
     157
     158/**
    132159 * Display search form.
    133160 *
    134161 * Will first attempt to locate the searchform.php file in either the child or