Opened 13 months ago
Last modified 13 months ago
#20660 new feature request
wp_get_attachment_url() ignores filter for unrecognized IDs
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | 3.3.2 |
| Severity: | minor | Keywords: | |
| Cc: |
Description
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;
Of course, modify the last part above to have {braces} around the section after the "if".