[wp-trac] [WordPress Trac] #51532: $tag_templates should be customizable (instead of local array)
WordPress Trac
noreply at wordpress.org
Thu Oct 15 10:54:19 UTC 2020
#51532: $tag_templates should be customizable (instead of local array)
-------------------------+-----------------------------
Reporter: xoomcoder | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
In file wp-includes/template-loader.php (lines 57 - 75), a local
associative array is defined: $tag_templates and it is used immediatly
after at line 79 in a foreach loop.
The problem:
So there's no way for a plugin or theme to customize the value of this
local variable.
Proposed enhancement:
* create a new public property in class WP_Query called $router_templates
(with same initial value as local variable $tag_templates)
{{{#!php
<?php
// wp-includes/class-wp-query.php
class WP_Query {
// ...
public $router_templates = array(
'is_embed' => 'get_embed_template',
'is_404' => 'get_404_template',
'is_search' => 'get_search_template',
'is_front_page' => 'get_front_page_template',
'is_home' => 'get_home_template',
'is_privacy_policy' => 'get_privacy_policy_template',
'is_post_type_archive' =>
'get_post_type_archive_template',
'is_tax' => 'get_taxonomy_template',
'is_attachment' => 'get_attachment_template',
'is_single' => 'get_single_template',
'is_page' => 'get_page_template',
'is_singular' => 'get_singular_template',
'is_category' => 'get_category_template',
'is_tag' => 'get_tag_template',
'is_author' => 'get_author_template',
'is_date' => 'get_date_template',
'is_archive' => 'get_archive_template',
);
}
}}}
* add a new function in wp-includes/template.php called
get_router_templates
{{{#!php
<?php
// ...
function get_router_templates ()
{
global $wp_query;
return apply_filters('router_templates', $wp_query->router_templates);
}
}}}
* upgrade the code in wp-includes/template-loader.php
{{{#!php
<?php
// line 55
if ( wp_using_themes() ) {
// line 57: Only modification: call function instead of defining local
array
$tag_templates = get_router_templates();
$template = false;
// Loop through each of the template conditionals, and find the
appropriate template file.
foreach ( $tag_templates as $tag => $template_getter ) {
// ...
}
}}}
* Impacts:
- There's no compatibility problem
- Perfomance impact is really light
- This will add more possibilities to the theme workflow.
* I can provide diff patch if needed
If you have questions, don't hesitate to ask.
Cheers.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51532>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list