Opened 9 years ago
Closed 9 years ago
#33277 closed defect (bug) (fixed)
Misleading comment for wp_get_attachment_link function
Reported by: | several27 | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.2.3 |
Component: | Media | Keywords: | has-patch 4.4-early commit |
Focuses: | Cc: |
Description
The comment for function wp_get_attachment_link inside wp-includes/post-template.php says that the first argument can be either int or WP_Post object, but that is not true.
This is the first line inside this function:
$id = intval($id);
This line will cause the error: Object of class WP_Post could not be converted to int.
Please forgive me any mistakes this is my first ticket :)
Attachments (3)
Change History (15)
#2
in reply to:
↑ 1
;
follow-up:
↓ 3
@
9 years ago
Replying to SergeyBiryukov:
Hi @several27, welcome to Trac and thanks for the report!
Introduced in [27473]. We could probably just remove the
intval()
and letget_post()
handle the value.
Would you like to try submitting a patch?
Hi and thank you for the incredibly quick answer :)
I just verified it and just removing intval()
won't work, line 1546: will have to be changed also:
$link_text = wp_get_attachment_image( $id, $size, $icon, $attr );
to
$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
And after that it should work (at least is working for me).
So how should I submit a patch?
#3
in reply to:
↑ 2
@
9 years ago
Replying to several27:
So how should I submit a patch?
https://make.wordpress.org/core/handbook/tutorials/trac/submitting-a-patch/
#5
@
9 years ago
- Keywords has-patch 4.4-early added; needs-patch removed
- Milestone changed from Awaiting Review to Future Release
#6
follow-up:
↓ 7
@
9 years ago
Just dug into this a bit and it looks like it has never supported a post object. The code was introduced in https://github.com/WordPress/WordPress/commit/0456afb16d10ad4ccc0d1a5a9b979f35ce7135e0 it looks like the previous function(get_the_attachment_link) that was deprecated also forced int. So is this just a problem with the function doc implying it can be a post object?
#7
in reply to:
↑ 6
;
follow-up:
↓ 8
@
9 years ago
Replying to MikeHansenMe:
So is this just a problem with the function doc stating it can be a post object?
Probably, and that's a bug. This patch solves it, and at the same time, it's an enhancement.
#8
in reply to:
↑ 7
@
9 years ago
Replying to knutsp:
Replying to MikeHansenMe:
So is this just a problem with the function doc stating it can be a post object?
Probably, and that's a bug. This patch solves it, and at the same time, it's an enhancement.
So, realistically, we should add a changelog entry mentioning that it now actually supports a WP_Post
object.
#11
@
9 years ago
- Focuses docs removed
- Keywords commit added
- Owner DrewAPicture deleted
33277.diff adds the changelog entry and regenerates the patch from root.
Hi @several27, welcome to Trac and thanks for the report!
Introduced in [27473]. We could probably just remove the
intval()
and letget_post()
handle the value.Would you like to try submitting a patch?