mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Media: Make sure attachment_url_to_postid() performs a case-sensitive search for the uploaded file name.
Previously, the first available match was returned, regardless of the case, which was not always the expected result. Props archon810, ben.greeley, tristangemus, vsamoletov, SergeyBiryukov. Fixes #39768. git-svn-id: https://develop.svn.wordpress.org/trunk@47010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4295,11 +4295,26 @@ function attachment_url_to_postid( $url ) {
|
||||
}
|
||||
|
||||
$sql = $wpdb->prepare(
|
||||
"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
|
||||
"SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
|
||||
$path
|
||||
);
|
||||
|
||||
$post_id = $wpdb->get_var( $sql );
|
||||
$results = $wpdb->get_results( $sql );
|
||||
$post_id = null;
|
||||
|
||||
if ( $results ) {
|
||||
// Use the first available result, but prefer a case-sensitive match, if exists.
|
||||
$post_id = reset( $results )->post_id;
|
||||
|
||||
if ( count( $results ) > 1 ) {
|
||||
foreach ( $results as $result ) {
|
||||
if ( $path === $result->meta_value ) {
|
||||
$post_id = $result->post_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an attachment id found by URL.
|
||||
|
||||
Reference in New Issue
Block a user