[wp-trac] [WordPress Trac] #18491: Calling wp_get_attachment_link with a non-existent ID throws PHP notice
WordPress Trac
wp-trac at lists.automattic.com
Sun Aug 21 00:55:08 UTC 2011
#18491: Calling wp_get_attachment_link with a non-existent ID throws PHP notice
------------------------------+-----------------------------
Reporter: Jayjdk | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Warnings/Notices | Version:
Severity: normal | Keywords: needs-patch
------------------------------+-----------------------------
If you're are using the `wp_get_attachment_link()` function with a non-
existent attachment ID, you'll get a notice.
Example:
`<?php echo wp_get_attachment_link( 9 ); ?>`
gives `Notice: Trying to get property of non-object in C:\wamp\www\theme
\wp-includes\post-template.php on line 1155`
As far I can see, the code causing it is this (wp-includes\post-
template.php on line 1155)
{{{
$_post = & get_post( $id );
if ( ('attachment' != $_post->post_type) || !$url =
wp_get_attachment_url($_post->ID) )
return __('Missing Attachment');
}}}
The $_post variable will be null in this case.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18491>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list