[wp-trac] [WordPress Trac] #13239: Filter locate_template template_names variable
WordPress Trac
noreply at wordpress.org
Tue Feb 18 01:48:32 UTC 2014
#13239: Filter locate_template template_names variable
--------------------------+-----------------------
Reporter: chrisbliss18 | Owner:
Type: enhancement | Status: reopened
Priority: normal | Milestone: 3.9
Component: Themes | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+-----------------------
Comment (by MikeSchinkel):
Replying to [comment:67 obenland]:
> How about casting `$template_names` to an array within the filter on
line 475?
Funny, that was how I wrote it initially. I reverted because I didn't
want the filter to have to check for a one element array with no value
which is what would happen if false, or an empty string was passed
''(which admittedly would be a very rare edge case.)''
> We could omit the `false === $template_names` check and remove the
typecasting from the foreach loop, while not changing the outcome for the
function.
Actually the purpose of the `false === $template_names` was to allow the
filter to return `false` if the hook wants to short-circuit template
loading. So omitting would change the outcome in some cases. I myself
have the same need in a library I've written where I want to run my own
`load_template()` because I want to be able to add a `$view` variable into
the template scope.
''(Another option way to solve my specific use-case besides short-
circuiting would be to add a filter in `load_template()` that would get
passed the name of `global` variables to add to the scope and then let the
hook add or remove them as needed. The return value would then use an
`extract()` on the array returned. But I don't know what other use-cases
for short-circuiting might exist so I don't know if my use-case is the
only one.)''
--
Ticket URL: <https://core.trac.wordpress.org/ticket/13239#comment:68>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list