Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#24714 closed defect (bug) (fixed)

get_template_part : !empty instead of isset ?

Reported by: tivnet's profile tivnet Owned by: nacin's profile 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)

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

Download all attachments as: .zip

Change History (9)

#1 @nacin
11 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 3.6

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

#2 @SergeyBiryukov
11 years ago

  • Component changed from General to Template
  • Version changed from trunk to 3.0

@MikeHansenMe
11 years ago

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

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

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
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to nacin:

In get_footer(), is that correct?

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

#6 @nacin
11 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 24617:

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

#7 @nacin
11 years ago

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

Note: See TracTickets for help on using tickets.