[wp-trac] [WordPress Trac] #40969: RFE: get_template_part() to return something or warn when nothing found
WordPress Trac
noreply at wordpress.org
Sun Jun 11 13:36:32 UTC 2017
#40969: RFE: get_template_part() to return something or warn when nothing found
-------------------------+------------------------------
Reporter: sphakka | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion | Focuses: template
-------------------------+------------------------------
Comment (by sphakka):
The problem is that `get_template_part( 'non-existing-file' )` fails
silently. Of course page rendering would break, so you'd see that
something is wrong, but that's not trivial without a message clue. The
rationale is that something like
{{{
if ( ! get_template_part( 'I_misspelled_this_one' )
error_log( 'I_misspelled_this_one: template file not found' );
}}}
would help spotting the mistake. It doesn't really need to report what it
found (returning bool would be fine), but since `locate_template()` is the
last statement in the code, then just having
{{{
return locate_template($templates, true, false);
}}}
would settle the matter with minimum effort ;-)
Actually, I now realize that this is an instance of a more general problem
with many (all?) `get_*()` functions calling `locate_template()` at end.
So, along the principle that silent failure is bad practice (unless I'm
missing some obscure reason for not having the possibility of checking
programmatically what goes on), a review of all those functions would be
advised. That would also make them more consistent with other
`get_whatever()` functions that already return something.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40969#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list