Opened 11 years ago
Closed 11 years ago
#28361 closed defect (bug) (fixed)
Twenty Ten, Eleven and Twelve: PHP notices due to undefined vars in attachment template
Reported by: |
|
Owned by: |
|
---|---|---|---|
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:
- Show E_NOTICE errors
- Display the page for any attachment, e.g: http://example.com/?attachment_id=115
Attachments (5)
Change History (16)
#3
follow-up:
↓ 4
@
11 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
#4
in reply to:
↑ 3
@
11 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:
- Enable E_NOTICE errors
- Enable Twentyten or Twentytwelve
- Go to the page for an image like http://example.com/?attachment_id=115 (I didn't test with other types)
#6
follow-up:
↓ 7
@
11 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
@
11 years ago
SergeyBiryukov You caught me red-handed, that was Polylang. My apologies.
#8
@
11 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.
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?