WordPress.org

Make WordPress Core

Ticket #13239: template.diff

File template.diff, 3.1 KB (added by kylejennings83, 3 years ago)

Proposed alternative patch

  • wp-includes/template.php

     
    4040         */
    4141        $templates = apply_filters( "{$type}_template_hierarchy", $templates );
    4242
    43         $template = locate_template( $templates );
     43        $template = locate_template( $templates, null, null, $type );
    4444
    4545        /**
    4646         * Filters the path of the queried template by type.
     
    613613        return get_query_template( 'attachment', $templates );
    614614}
    615615
     616
     617
    616618/**
    617619 * Retrieve the name of the highest priority template file that exists.
    618620 *
     
    626628 * @param bool         $require_once   Whether to require_once or require. Default true. Has no effect if $load is false.
    627629 * @return string The template filename if one is located.
    628630 */
    629 function locate_template($template_names, $load = false, $require_once = true ) {
    630         $located = '';
     631function locate_template($template_names, $load = false, $require_once = true, $type = null ) {
     632
     633    $located = '';
     634
     635    /**
     636         * Filters the path to the template files that are searched for when retrieving a template to use.
     637         *
     638         * If the filter is not triggered, the templates are expected to be in their default
     639         * location (the theme root).
     640         *
     641         * If the filter is triggered and a directory name is returned, then WordPress will
     642         * look in that directory (relative ancestor to the theme root) for the files.
     643         *
     644         * This filter also moves the location of all template parts such as header.php, footer.php ect ect
     645         * @since 4.7.0
     646         *
     647         * @param string $path A Directory name which contains all the template files, relative to the theme root.
     648         */
     649    $path = apply_filters("templates_path", '');
     650    $path = isset($path) ? trailingslashit($path) : $path;
     651
     652    /**
     653     * Filters the path to the template files, based on type, that are searched
     654     * for when retrieving a template to use.
     655     *
     656     *
     657         * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
     658         * 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
     659         *
     660     * @param string $path A Directory name which contains all the template files, relative to the theme root.
     661     */
     662    $path = apply_filters("{$type}_templates_path", $path);
     663    $path = isset($path) ? trailingslashit($path) : $path;
     664
     665
    631666        foreach ( (array) $template_names as $template_name ) {
    632667                if ( !$template_name )
    633668                        continue;
    634                 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
    635                         $located = STYLESHEETPATH . '/' . $template_name;
     669                if ( file_exists(STYLESHEETPATH . '/' . $path . $template_name)) {
     670                        $located = STYLESHEETPATH . '/' . $path . $template_name;
    636671                        break;
    637                 } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
    638                         $located = TEMPLATEPATH . '/' . $template_name;
     672                } elseif ( file_exists(TEMPLATEPATH . '/' . $path . $template_name) ) {
     673                        $located = TEMPLATEPATH . '/' . $path . $template_name;
    639674                        break;
    640675                } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
    641676                        $located = ABSPATH . WPINC . '/theme-compat/' . $template_name;