#24714 closed defect (bug) (fixed)
get_template_part : !empty instead of isset ?
Reported by: | tivnet | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Template | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
With a call like this one:
get_template_part( 'content', get_post_format() );
get_post_format()
may return false
, and then the following condition does not do what it should:
if ( isset($name) ) $templates[] = "{$slug}-{$name}.php";
and tries to load content-.php
Using !empty
instead of isset
should work better.
Attachments (2)
Change History (9)
#3
@
12 years ago
Actually, '0' is probably valid. Think get_template_part( 'something', get_query_var( 'paged' ) )
where an integer might be valid. Pagination generally starts with 1, but you get the idea.
False and null, cast to strings, equals ''
. That's what is happening anyway (as in, if you pass an array, we'll go looking for "something-Array.php"), so let's be explicit and add a check.
#4
follow-up:
↓ 5
@
12 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In 24616:
Note: See
TracTickets for help on using
tickets.
Could probably just be
if ( $name )
, as we know the variable is set.