[wp-trac] [WordPress Trac] #26636: There Is No Filter For get_sidebar()

WordPress Trac noreply at wordpress.org
Tue Jan 27 21:30:13 UTC 2015


#26636: There Is No Filter For get_sidebar()
-------------------------+------------------------------
 Reporter:  shelob9      |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Themes       |     Version:  1.5
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  template
-------------------------+------------------------------

Comment (by Shelob9):

 @justnorris

 I think, and I could be wrong, and I definitely do not speak for anyone
 with authority, but the opposition is to introducing several filters,
 'get_sidebar', 'get_header', 'get_footer', when each of the functions they
 will be in actually use `locate_template()`. Therefore, even though it
 would be less intuitive to use, we should add one filter in
 `locate_template()`.

 Then you could do something like:


 {{{
 add_filter( 'locate_template', function( $template ) {
 if ( 'sidebar.php' == $template ) {
         $template = 'something.php';
 }
 return $template;
 });
 }}}


 That's harder to use and would require more conditional logic, especially
 if you have multiple sidebars, but ti would work and now we only have one
 new filter, instead of three.

 I'd write that patch, but I know there is a long discussion in another
 ticket for refactoring `locate_template()`, so that would be a blocker.
 Also that discussion may result in a filter being added to
 `locate_template()` and then we don't exactly need a `get_sidebar` filter.

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


More information about the wp-trac mailing list