wp_get_attachment_url() ignores filter for unrecognized IDs
|Reported by:||RoamFree||Owned by:|
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.
$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;
Change History (4)
comment:2 c3mdigital — 8 months ago
- Resolution set to invalid
- Status changed from new to closed
- Version changed from 3.3.2 to 2.1
comment:3 markoheijnen — 8 months ago
- Resolution invalid deleted
- Status changed from closed to reopened