[wp-trac] [WordPress Trac] #20660: wp_get_attachment_url() ignores filter for unrecognized IDs
WordPress Trac
wp-trac at lists.automattic.com
Fri May 11 16:49:30 UTC 2012
#20660: wp_get_attachment_url() ignores filter for unrecognized IDs
-----------------------------+-----------------------------
Reporter: RoamFree | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.3.2
Severity: minor | Keywords:
-----------------------------+-----------------------------
wp_get_attachment_url() fails to invoke its filters when it encounters an
unrecognized post ID. It would be helpful to allow a filter to deal with
the situation.
The plugin NextGEN Gallery uses image IDs like "ngg-1", while WP's image
IDs are integers. A filter could deal with the situation.
wp_get_attachment_url() begins like this:
{{{
$post_id = (int) $post_id;
if ( !$post =& get_post( $post_id ) )
return false;
}}}
Obviously, a nonstandard post ID will ignore the filters. If the filters
were invoked, nonstandard IDs can be dealt with as desired by themes or
plugins.
The filter should be given a "false" value instead of $url, and the
original $post_id value (before forcing to (int)). If existing filters
are already dealing with null or empty URLs, they can handle this
situation.
Suggestion:
{{{
$post_id_original = $post_id;
$post_id = (int) $post_id;
if ( !$post =& get_post( $post_id ) )
$url = apply_filters( 'wp_get_attachment_url', false, $post_id_original
);
if ( empty( $url ) )
return false;
return $url;
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20660>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list