[wp-trac] [WordPress Trac] #42855: Add ability to filter header, sidebar, searchform, footer and template_part file paths

WordPress Trac noreply at wordpress.org
Sun Feb 18 09:28:06 UTC 2018


#42855: Add ability to filter header, sidebar, searchform, footer and template_part
file paths
------------------------------+------------------------------
 Reporter:  atanasangelovdev  |       Owner:
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Themes            |     Version:
 Severity:  normal            |  Resolution:
 Keywords:  has-patch         |     Focuses:  template
------------------------------+------------------------------

Comment (by atanasangelovdev):

 Thank you for the feedback, @joyously, I really appreciate it.

 A few rebuttals, If I may:

 > Since locate_template() is not checking for directory traversal, but is
 checking for 3 specific folders, it is best that the theme and child theme
 are the only code that can influence what is loaded ...
 > If there is a filter, not only could the template part name be changed,
 but the path to it could be changed, and that just doesn't seem right ...
 > ... allowing a filter on a part of a theme template breaks the integrity
 of the theme.

 Except the `template_include` filter exists which can do exactly what you
 argue should not be allowed. Also, "doesn't seem right" is not a valid
 argument.

 > The child theme can change it easily ...

 This is not entirely correct. Yes, you can change the contents of a
 partial but if you wish to change the location of a partial you have to
 essentially copy-paste the parent partial/template and change how it loads
 the partial you wish to move.

 > ... so it's only plugins that would "benefit" from a filter ...

 I ended up suggesting this filter because we are building a starter theme,
 not a plugin, and wanted to reorganize the template/view files away from
 dotfiles, library code, classes etc. but could not do so to a satisfactory
 level since core template partials are required to exist and are locked to
 be in the same directory as the style.css file (this is just one example).

 > ... they would have to specify a relative path to the plugin because
 only 3 theme folders are checked for the file.

 I agree on this point - I can see relative paths from themes to plugin
 being used and there should be a better solution for this.

 > It actually doesn't make sense to me to have get_header() able to get
 something other than the header that the theme defined.

 It does not necessarily have to be something different. It can be the
 header, just in another place or with a fallback. Also the filter does not
 apply only to core partials but to any partial loaded using
 `get_template_part()`.

 ----

 I would really like to stress that the above are just example use cases.
 @MikeSchinkel has mentioned several other valid use cases that I believe
 are important (and which convinced @johnbillion to reopen the ticket) and
 are left without a response/rebuttal:
 https://core.trac.wordpress.org/ticket/21062#comment:19

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42855#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list