| @@ -1842,8 +1842,12 @@ | ||
| 1842 | 1842 | $image_id = get_post_thumbnail_id($post); |
| 1843 | 1843 | if ($image_id) { |
| 1844 | 1844 | $image_data = wp_get_attachment_image_src($image_id, 'large'); |
| 1845 | 1845 | if (!empty($image_data[0])) { |
| 1846 | + // The ID is in hand here and gone once this returns a | |
| 1847 | + // bare URL; say so rather than have the tag builders look | |
| 1848 | + // it up again, twice, with a URL core cannot match (#847). | |
| 1849 | + Attachment_Lookup::remember((string) $image_data[0], (int) $image_id); | |
| 1846 | 1850 | return $image_data[0]; |
| 1847 | 1851 | } |
| 1848 | 1852 | } |
| 1849 | 1853 | } |
| @@ -1890,8 +1894,12 @@ | ||
| 1890 | 1894 | $image_id = get_post_thumbnail_id($post); |
| 1891 | 1895 | if ($image_id) { |
| 1892 | 1896 | $image_data = wp_get_attachment_image_src($image_id, 'large'); |
| 1893 | 1897 | if (!empty($image_data[0])) { |
| 1898 | + // The ID is in hand here and gone once this returns a | |
| 1899 | + // bare URL; say so rather than have the tag builders look | |
| 1900 | + // it up again, twice, with a URL core cannot match (#847). | |
| 1901 | + Attachment_Lookup::remember((string) $image_data[0], (int) $image_id); | |
| 1894 | 1902 | return $image_data[0]; |
| 1895 | 1903 | } |
| 1896 | 1904 | } |
| 1897 | 1905 | } |
| @@ -2184,21 +2192,23 @@ | ||
| 2184 | 2192 | if (empty($image_url)) { |
| 2185 | 2193 | return $image_data; |
| 2186 | 2194 | } |
| 2187 | 2195 | |
| 2188 | - // Get image metadata | |
| 2189 | - $attachment_id = attachment_url_to_postid($image_url); | |
| 2196 | + // Get image metadata. The dimensions are those of the file this URL | |
| 2197 | + // names — usually a generated size — not of the original upload, so | |
| 2198 | + // the width and height published beside it describe the same image. | |
| 2199 | + $attachment_id = Attachment_Lookup::id_from_url($image_url); | |
| 2190 | 2200 | if ($attachment_id) { |
| 2191 | 2201 | $image_meta = wp_get_attachment_metadata($attachment_id); |
| 2192 | 2202 | $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); |
| 2193 | - $mime_type = get_post_mime_type($attachment_id); | |
| 2203 | + $image_file = Attachment_Lookup::describe($attachment_id, $image_url); | |
| 2194 | 2204 | |
| 2195 | 2205 | if ($image_meta && isset($image_meta['width'], $image_meta['height'])) { |
| 2196 | - $width = (int) $image_meta['width']; | |
| 2197 | - $height = (int) $image_meta['height']; | |
| 2206 | + $width = $image_file['width']; | |
| 2207 | + $height = $image_file['height']; | |
| 2198 | 2208 | |
| 2199 | 2209 | $image_data['alt'] = $image_alt ?: ''; |
| 2200 | - $image_data['type'] = $mime_type ?: ''; | |
| 2210 | + $image_data['type'] = $image_file['type']; | |
| 2201 | 2211 | |
| 2202 | 2212 | // SVGs and other vector uploads store 0x0 metadata. Dimension |
| 2203 | 2213 | // checks are meaningless there and dividing by 0 is fatal. |
| 2204 | 2214 | if ($width > 0 && $height > 0) { |
| @@ -2250,8 +2260,9 @@ | ||
| 2250 | 2260 | $custom_logo_id = get_theme_mod('custom_logo'); |
| 2251 | 2261 | if ($custom_logo_id) { |
| 2252 | 2262 | $logo_data = wp_get_attachment_image_src($custom_logo_id, 'large'); |
| 2253 | 2263 | if ($logo_data) { |
| 2264 | + Attachment_Lookup::remember((string) $logo_data[0], (int) $custom_logo_id); | |
| 2254 | 2265 | return $logo_data[0]; |
| 2255 | 2266 | } |
| 2256 | 2267 | } |
| 2257 | 2268 | |
| @@ -2259,8 +2270,9 @@ | ||
| 2259 | 2270 | $site_icon_id = get_option('site_icon'); |
| 2260 | 2271 | if ($site_icon_id) { |
| 2261 | 2272 | $icon_data = wp_get_attachment_image_src($site_icon_id, 'large'); |
| 2262 | 2273 | if ($icon_data) { |
| 2274 | + Attachment_Lookup::remember((string) $icon_data[0], (int) $site_icon_id); | |
| 2263 | 2275 | return $icon_data[0]; |
| 2264 | 2276 | } |
| 2265 | 2277 | } |
| 2266 | 2278 | |
| @@ -3017,13 +3029,14 @@ | ||
| 3017 | 3029 | return $validation; |
| 3018 | 3030 | } |
| 3019 | 3031 | |
| 3020 | 3032 | // Get image metadata if it's a local attachment |
| 3021 | - $attachment_id = attachment_url_to_postid($image_url); | |
| 3033 | + $attachment_id = Attachment_Lookup::id_from_url($image_url); | |
| 3022 | 3034 | if ($attachment_id) { |
| 3023 | 3035 | $image_meta = wp_get_attachment_metadata($attachment_id); |
| 3024 | - $meta_width = isset($image_meta['width']) ? (int) $image_meta['width'] : 0; | |
| 3025 | - $meta_height = isset($image_meta['height']) ? (int) $image_meta['height'] : 0; | |
| 3036 | + $image_file = Attachment_Lookup::describe($attachment_id, $image_url); | |
| 3037 | + $meta_width = $image_file['width']; | |
| 3038 | + $meta_height = $image_file['height']; | |
| 3026 | 3039 | |
| 3027 | 3040 | // SVGs and other vector uploads store 0x0 metadata — skip the |
| 3028 | 3041 | // dimension/ratio checks instead of dividing by 0. |
| 3029 | 3042 | if ($image_meta && $meta_width > 0 && $meta_height > 0) { |