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;