WordPress.org

Make WordPress Core

Ticket #13239: 13239.8.diff

File 13239.8.diff, 2.3 KB (added by MikeSchinkel, 7 years ago)

Based on 13239.2, adds hook docs, follows new brace standard, captures/uses $filepath and adds short-circuit.

  • wp-includes/template.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    453453 * inherit from a parent theme can just overload one file.
    454454 *
    455455 * @since 2.7.0
     456 * @uses apply_filters() Calls 'locate_template' filter on array of template names.
    456457 *
    457458 * @param string|array $template_names Template file(s) to search for, in order.
    458459 * @param bool $load If true the template file will be loaded if it is found.
    459460 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
    460461 * @return string The template filename if one is located.
    461462 */
    462 function locate_template($template_names, $load = false, $require_once = true ) {
     463function locate_template( $template_names, $load = false, $require_once = true ) {
    463464        $located = '';
    464         foreach ( (array) $template_names as $template_name ) {
    465                 if ( !$template_name )
     465
     466        /**
     467         * Filter the array of template names passed to locate_filter().
     468         *
     469         * Returning false will signal to locate_template() to simply return and not load any template.
     470         *
     471         * @since 3.9.0
     472         *
     473         * @param string|array $template_names Template file or array of files to search for, in order.
     474         */
     475        $template_names = apply_filters( 'locate_template', $template_names );
     476
     477        if ( false === $template_names )
     478                return false;
     479
     480        foreach ( (array)$template_names as $template_name ) {
     481                if ( ! $template_name ) {
    466482                        continue;
    467                 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
    468                         $located = STYLESHEETPATH . '/' . $template_name;
     483                } else if ( path_is_absolute( $template_name ) && file_exists( $template_name ) ) {
     484                        $located = $template_name;
     485                } else if ( file_exists( $filepath = get_stylesheet_directory() . '/' . $template_name ) ) {
     486                        $located = $filepath;
    469487                        break;
    470                 } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
    471                         $located = TEMPLATEPATH . '/' . $template_name;
     488                } else if ( $filepath = file_exists( $filepath = get_template_directory() . '/' . $template_name ) ) {
     489                        $located = $filepath;
    472490                        break;
    473491                }
    474492        }
    475493
    476         if ( $load && '' != $located )
     494        if ( $load && '' != $located ) {
    477495                load_template( $located, $require_once );
     496        }
    478497
    479498        return $located;
    480499}