Ticket #42855: 42855.patch
File 42855.patch, 3.4 KB (added by , 7 years ago) |
---|
-
src/wp-includes/general-template.php
7 7 */ 8 8 9 9 /** 10 * Get a template part's template hierarchy. 11 * 12 * For the $name parameter, if the file is called "{slug}-special.php" then specify 13 * "special". 14 * 15 * @param string $slug The slug name for the generic template. 16 * @param string $name The name of the specialised template. 17 * @return string[] Template part's template hierarchy. 18 */ 19 function get_template_part_hierarchy( $slug, $name = null ) { 20 $templates = array(); 21 $formatted_name = (string) $name; 22 if ( '' !== $formatted_name ) { 23 $templates[] = "{$slug}-{$formatted_name}.php"; 24 } 25 26 $templates[] = "{$slug}.php"; 27 28 /** 29 * Filters the template part template hierarchy. 30 * 31 * The dynamic portion of the hook name, `$slug`, refers to the slug name 32 * for the generic template part. 33 * 34 * @param string[] $templates The template part template hierarchy. 35 * @param string $slug The slug name for the generic template. 36 * @param string|null $name The name of the specialised template. 37 */ 38 $templates = apply_filters( "template_part_{$slug}_template_hierarchy", $templates, $slug, $name ); 39 40 return $templates; 41 } 42 43 /** 10 44 * Load header template. 11 45 * 12 46 * Includes the header template for a theme or if a name is specified then a … … 30 64 */ 31 65 do_action( 'get_header', $name ); 32 66 33 $templates = array(); 34 $name = (string) $name; 35 if ( '' !== $name ) { 36 $templates[] = "header-{$name}.php"; 37 } 67 $templates = get_template_part_hierarchy( 'header', $name ); 38 68 39 $templates[] = 'header.php';40 41 69 locate_template( $templates, true ); 42 70 } 43 71 … … 65 93 */ 66 94 do_action( 'get_footer', $name ); 67 95 68 $templates = array(); 69 $name = (string) $name; 70 if ( '' !== $name ) { 71 $templates[] = "footer-{$name}.php"; 72 } 96 $templates = get_template_part_hierarchy( 'footer', $name ); 73 97 74 $templates[] = 'footer.php';75 76 98 locate_template( $templates, true ); 77 99 } 78 100 … … 100 122 */ 101 123 do_action( 'get_sidebar', $name ); 102 124 103 $templates = array(); 104 $name = (string) $name; 105 if ( '' !== $name ) { 106 $templates[] = "sidebar-{$name}.php"; 107 } 125 $templates = get_template_part_hierarchy( 'sidebar', $name ); 108 126 109 $templates[] = 'sidebar.php';110 111 127 locate_template( $templates, true ); 112 128 } 113 129 … … 142 158 * @since 3.0.0 143 159 * 144 160 * @param string $slug The slug name for the generic template. 145 * @param string|null $name The name of the speciali zed template.161 * @param string|null $name The name of the specialised template. 146 162 */ 147 163 do_action( "get_template_part_{$slug}", $slug, $name ); 148 164 149 $templates = array(); 150 $name = (string) $name; 151 if ( '' !== $name ) { 152 $templates[] = "{$slug}-{$name}.php"; 153 } 165 $templates = get_template_part_hierarchy( $slug, $name ); 154 166 155 $templates[] = "{$slug}.php";156 157 167 locate_template( $templates, true, false ); 158 168 } 159 169 … … 202 212 */ 203 213 $format = apply_filters( 'search_form_format', $format ); 204 214 205 $search_form_template = locate_template( 'searchform.php' ); 215 $template_hierarchy = get_template_part_hierarchy( 'searchform' ); 216 $search_form_template = locate_template( $template_hierarchy ); 206 217 if ( '' != $search_form_template ) { 207 218 ob_start(); 208 219 require( $search_form_template );