Make WordPress Core

Ticket #13239: template.php.diff

File template.php.diff, 1.4 KB (added by aristath, 9 years ago)

adds a 'locate_template' filter

  • template.php

     
    496496 * @param bool         $require_once   Whether to require_once or require. Default true. Has no effect if $load is false.
    497497 * @return string The template filename if one is located.
    498498 */
    499 function locate_template($template_names, $load = false, $require_once = true ) {
     499function locate_template( $template_names, $load = false, $require_once = true ) {
    500500        $located = '';
    501501        foreach ( (array) $template_names as $template_name ) {
    502                 if ( !$template_name )
     502                if ( ! $template_name )
    503503                        continue;
    504                 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
     504                if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
    505505                        $located = STYLESHEETPATH . '/' . $template_name;
    506506                        break;
    507                 } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
     507                } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
    508508                        $located = TEMPLATEPATH . '/' . $template_name;
    509509                        break;
    510510                }
    511511        }
    512512
    513         if ( $load && '' != $located )
     513        // Allow overriding the template location using the 'locate_template' filter
     514        $located = apply_filters( 'locate_template', $located );
     515
     516        if ( $load && '' != $located ) {
    514517                load_template( $located, $require_once );
     518        }
    515519
    516520        return $located;
    517521}
     
    557561                require( $_template_file );
    558562        }
    559563}
    560