[wp-trac] [WordPress Trac] #39768: Incorrect image returned with attachment_url_to_postid()
WordPress Trac
noreply at wordpress.org
Thu Feb 2 15:39:21 UTC 2017
#39768: Incorrect image returned with attachment_url_to_postid()
--------------------------+-----------------------------
Reporter: ben.greeley | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.7.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When two files are uploaded to the media library during the same month
that have the same name and differ in capitalization, the function
{{{
attachment_url_to_postid()
}}}
can return the incorrect image.
For example, if two images were uploaded named untitled.jpg and
Untitled.jpg, the SQL query that is being run in
{{{
attachment_url_to_postid()
}}}
isn't case-sensitive so it will use the first image that is returned,
which may not be correct if the desired image is Untitled.jpg, but the
image information that is returned is for untitled.jpg. The meta_value for
each _wp_attached_file is saved as 2017/02/untitled.jpg and
2017/02/Untitled-1.jpg, so a query to match http://url.dev/wp-
content/uploads/sites/9/2017/02/Untitled.jpg returns 2017/02/untitled.jpg,
which is the incorrect image.
I created a suggested workaround, which grabs matches in case there was a
duplicate filename and returns the closest case-sensitive result.
https://gist.github.com/bengreeley/29a6edaca5c370091dd2cafc3369e400
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39768>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list