[wp-trac] [WordPress Trac] #13265: Filter results of get_page_templates()
WordPress Trac
noreply at wordpress.org
Sat Mar 1 18:56:55 UTC 2014
#13265: Filter results of get_page_templates()
-------------------------+-------------------------
Reporter: nathanrice | Owner: nathanrice
Type: enhancement | Status: reopened
Priority: normal | Milestone: 3.9
Component: Themes | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch | Focuses: template
-------------------------+-------------------------
Comment (by nacin):
[attachment:13265.diff] adds post context to the filter. This would be
necessary so as not to rely on the global post for things like deprecating
a template and only allowing it to be used for posts that already use it.
> Would you be able to summarize the concerns you see for adding templates
and/or potential scenarios where adding might be a problem?
At the moment, page template values are relative paths to physical
template files. I'll be honest, the proposed plugins are cleaner than I
was expecting, but the use of the template_include hook has me wanting
something a bit better.
I suppose this could work:
{{{
add_filter( 'page_templates', function( $templates ) {
$template['my_plugin_template_one'] = 'My Plugin Template';
});
add_filter( 'page_template', function( $template ) {
if ( is_page_template( 'my_plugin_template_one' ) ) {
return dirname( __FILE__ ) . '/templates/one.php';
}
return $template;
});
}}}
Something feels wrong about it. Page templates are fairly rigid, are only
available for pages, and are intrinsic to the theme. For nearly all use
cases, a plugin can't just call get_header() and get_footer() and pray the
markup will work. It makes sense that a child theme or a parent theme
needs to register them, at least in their current form. That's more of an
indictment of themes, yes, but my point is templates in plugins just don't
work well. So should we encourage what is a certain level of "slop"?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/13265#comment:50>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list