Make WordPress Core

Ticket #13239: 13239.template.php.diff

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

adds a 'locate_template' filter (including inline docs)

  • 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                }
     505                if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
    505506                        $located = STYLESHEETPATH . '/' . $template_name;
    506507                        break;
    507                 } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
     508                } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
    508509                        $located = TEMPLATEPATH . '/' . $template_name;
    509510                        break;
    510511                }
    511512        }
    512513
    513         if ( $load && '' != $located )
     514        /**
     515         * Filter the path of the template.
     516         *
     517         * @since 4.3.0
     518         *
     519         * @param string $located Path to the template.
     520         */
     521        $located = apply_filters( 'locate_template', $located );
     522
     523        if ( $load && '' != $located ) {
    514524                load_template( $located, $require_once );
     525        }
    515526
    516527        return $located;
    517528}
     
    557568                require( $_template_file );
    558569        }
    559570}
    560