WordPress.org

Make WordPress Core

Ticket #22355: 27322.diff

File 27322.diff, 2.3 KB (added by rmccue, 6 years ago)

Patch from #27322

  • wp-includes/template.php

    diff --git wp-includes/template.php wp-includes/template.php
    index 9802447..ff26c75 100644
    function get_comments_popup_template() { 
    447447}
    448448
    449449/**
     450 * Get theme directories
     451 *
     452 * Gives a map of theme base directories to theme base URIs, allowing searching
     453 * themes for a certain file in order.
     454 *
     455 * @return array Map of base directory to base URI
     456 */
     457function wp_template_directories() {
     458        $directories = array(
     459                get_stylesheet_directory() => get_stylesheet_directory_uri(),
     460                get_template_directory() => get_template_directory_uri(),
     461        );
     462        return apply_filters( 'wp_template_directories', $directories );
     463}
     464
     465/**
    450466 * Retrieve the name of the highest priority template file that exists.
    451467 *
    452468 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
    function get_comments_popup_template() { 
    461477 */
    462478function locate_template($template_names, $load = false, $require_once = true ) {
    463479        $located = '';
     480        $basedirs = array_keys( wp_template_directories() );
    464481        foreach ( (array) $template_names as $template_name ) {
    465482                if ( !$template_name )
    466483                        continue;
    467                 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
    468                         $located = STYLESHEETPATH . '/' . $template_name;
    469                         break;
    470                 } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
    471                         $located = TEMPLATEPATH . '/' . $template_name;
    472                         break;
     484
     485                foreach ( $basedirs as $directory ) {
     486                        if ( file_exists( $directory . '/' . $template_name ) ) {
     487                                $located = $directory . '/' . $template_name;
     488                                break 2;
     489                        }
    473490                }
    474491        }
    475492
    function load_template( $_template_file, $require_once = true ) { 
    503520                require( $_template_file );
    504521}
    505522
     523/**
     524 * Get URI for an image
     525 *
     526 * Uses {@see wp_template_directories} to first find the file, then get the
     527 * relevant URI for it.
     528 *
     529 * @param string $file File name to search for
     530 * @return string URI for the asset, empty string if none found
     531 */
     532function theme_url( $file ) {
     533        $directories = wp_template_directories();
     534        $uri = '';
     535
     536        foreach ( $directories as $directory => $base_uri ) {
     537                $path = sprintf( '%s/%s', $directory, $file );
     538                if ( file_exists( $path ) ) {
     539                        $uri = sprintf( '%s/%s', $base_uri, $file );
     540                        break;
     541                }
     542        }
     543
     544        return apply_filters( 'theme_url', $uri, $file, $directories );
     545}
     546