| @@ -85,18 +85,21 @@ | ||
| 85 | 85 | |
| 86 | 86 | $results = $wpdb->get_results($sql); |
| 87 | 87 | $post_id = null; |
| 88 | 88 | |
| 89 | - if ($results) { | |
| 90 | - // Use the first available result, but prefer a case-sensitive match, if exists. | |
| 91 | - $post_id = reset($results)->post_id; | |
| 89 | + if (count($results) > 0) { | |
| 90 | + $contains_slash = strpos($path, '/'); | |
| 92 | 91 | |
| 93 | - if (count($results) > 1) { | |
| 94 | - foreach ($results as $result) { | |
| 95 | - if ($path === $result->meta_value) { | |
| 96 | - $post_id = $result->post_id; | |
| 97 | - break; | |
| 98 | - } | |
| 92 | + foreach ($results as $result) { | |
| 93 | + if ($path === $result->meta_value) { | |
| 94 | + | |
| 95 | + // escape if we have a direct match, if not return | |
| 96 | + $post_id = $result->post_id; | |
| 97 | + break; | |
| 98 | + } elseif (!$contains_slash && $path === basename($result->meta_value)) { | |
| 99 | + | |
| 100 | + // escape if we are only matching the filename | |
| 101 | + $post_id = $result->post_id; | |
| 99 | 102 | } |
| 100 | 103 | } |
| 101 | 104 | } |
| 102 | 105 | |