Ticket #12877: 12877.patch
File 12877.patch, 4.0 KB (added by , 14 years ago) |
---|
-
wp-includes/template-loader.php
18 18 return; 19 19 endif; 20 20 21 /** 22 * Locates and loads the template for current page ($wp_query). 23 * 24 * @since 3.1.0 25 */ 26 function template_loader() { 21 27 if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) : 22 28 $template = false; 23 29 if ( is_404() && $template = get_404_template() ) : … … 43 49 include( $template ); 44 50 return; 45 51 endif; 52 } 46 53 54 update_template_hierarchy(); 55 template_loader(); 56 47 57 ?> -
wp-includes/theme.php
1042 1042 * @return string The template filename if one is located. 1043 1043 */ 1044 1044 function locate_template($template_names, $load = false, $require_once = true ) { 1045 $template_names = apply_filters('locate_template', $template_names); 1046 1045 1047 if ( !is_array($template_names) ) 1046 1048 return ''; 1047 1049 … … 1089 1091 } 1090 1092 1091 1093 /** 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 */ 1101 function 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 */ 1120 function 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 */ 1138 function _record_template_hierarchy( $template_names ) { 1139 global $wp_template_hierarchy; 1140 $wp_template_hierarchy[] = $template_names; 1141 return false; 1142 } 1143 1144 /** 1092 1145 * Display localized stylesheet link element. 1093 1146 * 1094 1147 * @since 2.1.0 -
wp-includes/general-template.php
129 129 } 130 130 131 131 /** 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 */ 148 function 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 /** 132 161 * Display search form. 133 162 * 134 163 * Will first attempt to locate the searchform.php file in either the child or