From fc1d327261825c1a54f29d31fda0ea6c4a1cfc3e Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 23 Mar 2015 17:23:27 +0000 Subject: [PATCH] Introduce `attachment_url_to_postid` filter to let plugins manage the uploads location better. Props mattwiebe. Fixes #31717. git-svn-id: https://develop.svn.wordpress.org/trunk@31867 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 282e68a0c5..9c04e9c7ac 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -3409,6 +3409,16 @@ function attachment_url_to_postid( $url ) { ); $post_id = $wpdb->get_var( $sql ); + /** + * Filter an attachment id found by URL. + * + * @since 4.2.0 + * + * @param int|null $post_id The post_id (if any) found by the function. + * @param string $url The URL being looked up. + */ + $post_id = apply_filters( 'attachment_url_to_postid', $post_id, $url ); + return (int) $post_id; }