Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#28361 closed defect (bug) (fixed)

Twenty Ten, Eleven and Twelve: PHP notices due to undefined vars in attachment template

Reported by: nabil_kadimi's profile nabil_kadimi Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.0 Priority: normal
Severity: minor Version: 4.0
Component: Bundled Theme Keywords: has-patch commit
Focuses: Cc:

Description

I got a few errors while viewing attachments

Notice: Undefined variable: k in... 

To reproduce:

Attachments (5)

28361.patch (1.4 KB) - added by nabil_kadimi 10 years ago.
28361-1.patch (2.2 KB) - added by nabil_kadimi 10 years ago.
28361.png (1.5 MB) - added by nabil_kadimi 10 years ago.
28361-1.jpg (246.6 KB) - added by nabil_kadimi 10 years ago.
28361.2.patch (2.9 KB) - added by SergeyBiryukov 10 years ago.

Download all attachments as: .zip

Change History (16)

@nabil_kadimi
10 years ago

#1 @nabil_kadimi
10 years ago

  • Keywords has-patch added
  • Severity changed from normal to minor

#2 @nabil_kadimi
10 years ago

  • Component changed from Themes to Bundled Theme

#3 follow-up: @lancewillett
10 years ago

  • Milestone changed from Awaiting Review to 4.0
  • Summary changed from Twentyten/Twentytwelve: PHP notices due to undefined vars to Twenty Ten, Eleven and Twelve: PHP notices due to undefined vars in attachment template

Thanks for the report. Can you tell us how to repeat, maybe what kind of attachment you were viewing? Was it an image or something else?

#4 in reply to: ↑ 3 @nabil_kadimi
10 years ago

Replying to lancewillett:

Thanks for the report. Can you tell us how to repeat, maybe what kind of attachment you were viewing? Was it an image or something else?

I tried with an image and got these errors.

To reproduce:

#5 @nabil_kadimi
10 years ago

I reinstalled from trunk and was able to see one more error, patch updated

@nabil_kadimi
10 years ago

@nabil_kadimi
10 years ago

#6 follow-up: @SergeyBiryukov
10 years ago

The only way for $k to be empty here is for get_children() to return an empty array a few lines above. I could not reproduce that. Do you have a plugin or a custom function that modifies all queries via pre_get_posts filter?

We could just move $k++; to the if ( count( $attachments ) > 1 ) branch a few lines below. However, it seems like we're patching the symptom here rather than the root cause.

#7 in reply to: ↑ 6 @nabil_kadimi
10 years ago

SergeyBiryukov You caught me red-handed, that was Polylang. My apologies.

#8 @SergeyBiryukov
10 years ago

  • Keywords commit added

I guess we should still avoid the notice here.

28361.2.patch moves $k++ to the if ( count( $attachments ) > 1 ) branch and also makes adjacent_image_link() more consistent with get_adjacent_post_link(), which has a check for a valid post object: tags/3.9.1/src/wp-includes/link-template.php#L1807.

#9 @nabil_kadimi
10 years ago

That's awesome, thanks.

#10 @SergeyBiryukov
10 years ago

In 28584:

Avoid a PHP notice in adjacent_image_link() if no images were found.

props nabil_kadimi.
see #28361.

#11 @SergeyBiryukov
10 years ago

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

In 28585:

Avoid a PHP notice in bundled themes if no images were found.

props nabil_kadimi.
fixes #28361.

Note: See TracTickets for help on using tickets.