Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#24714 closed defect (bug) (fixed)

get_template_part : !empty instead of isset ?

Reported by: tivnet Owned by: nacin
Priority: normal Milestone: 3.6
Component: Template Version: 3.0
Severity: normal Keywords: has-patch commit
Cc: Focuses:

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)

general-template.php.patch (407 bytes ) - added by tivnet 13 years ago.
24714.diff (534 bytes ) - added by MikeHansenMe 13 years ago.

Download all attachments as: .zip

Change History (9)

#1 @nacin
13 years ago

  • Keywords commit added
  • Milestone Awaiting Review3.6

Could probably just be if ( $name ), as we know the variable is set.

#2 @SergeyBiryukov
13 years ago

  • Component GeneralTemplate
  • Version trunk3.0

@MikeHansenMe
13 years ago

#3 @nacin
13 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: @nacin
13 years ago

  • Owner set to nacin
  • Resolutionfixed
  • Status newclosed

In 24616:

In general template functions, cast to string then ensure we actually have a template name before proceeding. Affects get_sidebar(), get_header(), get_footer(), get_template_part().

props tivnet for initial patch.
fixes #24714.

#5 in reply to: ↑ 4 @tivnet
13 years ago

  • Resolution fixed
  • Status closedreopened

Replying to nacin:

In get_footer(), is that correct?

$name = (string) $name;
	if ( null !== $name && false !== $name )

#6 @nacin
13 years ago

  • Resolutionfixed
  • Status reopenedclosed

In 24617:

Have get_footer() match get_header() etc in [24616]. fixes #24714.

#7 @nacin
13 years ago

Thanks tivnet. That was me experimenting with some alternative logic, and it snuck in.

Note: See TracTickets for help on using tickets.