| 1 | Index: template.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- template.php (revision 38766) |
|---|
| 4 | +++ template.php (working copy) |
|---|
| 5 | @@ -539,23 +539,43 @@ |
|---|
| 6 | */ |
|---|
| 7 | function locate_template($template_names, $load = false, $require_once = true ) { |
|---|
| 8 | $located = ''; |
|---|
| 9 | + $locations = array( |
|---|
| 10 | + get_stylesheet_directory(), |
|---|
| 11 | + get_template_directory() |
|---|
| 12 | + ); |
|---|
| 13 | + |
|---|
| 14 | + /** |
|---|
| 15 | + * Filter the possible template locations. |
|---|
| 16 | + * |
|---|
| 17 | + * @param array $locations Possible template locations. |
|---|
| 18 | + */ |
|---|
| 19 | + $locations = apply_filters( 'template_locations', $locations ); |
|---|
| 20 | + |
|---|
| 21 | foreach ( (array) $template_names as $template_name ) { |
|---|
| 22 | - if ( !$template_name ) |
|---|
| 23 | + if ( !$template_name ) { |
|---|
| 24 | continue; |
|---|
| 25 | - if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { |
|---|
| 26 | - $located = STYLESHEETPATH . '/' . $template_name; |
|---|
| 27 | - break; |
|---|
| 28 | - } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { |
|---|
| 29 | - $located = TEMPLATEPATH . '/' . $template_name; |
|---|
| 30 | - break; |
|---|
| 31 | - } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { |
|---|
| 32 | - $located = ABSPATH . WPINC . '/theme-compat/' . $template_name; |
|---|
| 33 | - break; |
|---|
| 34 | } |
|---|
| 35 | + |
|---|
| 36 | + foreach ( (array) $locations as $location ) { |
|---|
| 37 | + $template = trailingslashit( $location ) . $template_name; |
|---|
| 38 | + if ( file_exists( $template ) { |
|---|
| 39 | + $located = $template; |
|---|
| 40 | + break; |
|---|
| 41 | + } |
|---|
| 42 | + } |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | - if ( $load && '' != $located ) |
|---|
| 46 | + /** |
|---|
| 47 | + * Filter the set template location |
|---|
| 48 | + * |
|---|
| 49 | + * @param string $located Generated template location. |
|---|
| 50 | + * @param array $templates_names Possible template names. |
|---|
| 51 | + */ |
|---|
| 52 | + $located = apply_filters( 'locate_template', $located, $template_names ); |
|---|
| 53 | + |
|---|
| 54 | + if ( $load && '' != $located ) { |
|---|
| 55 | load_template( $located, $require_once ); |
|---|
| 56 | + } |
|---|
| 57 | |
|---|
| 58 | return $located; |
|---|
| 59 | } |
|---|