PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.12.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.12.0
2.12.0 2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk All 53 releases
← All changes | includes/seo/class-site-identity-manager.php +16 -22 2.10.0 → 2.12.0 View file →
@@ -508,11 +508,12 @@
508 508 * Attachment ID behind a configured icon URL, or 0 when it is not ours.
509 509 *
510 510 * attachment_url_to_postid() matches _wp_attached_file, which holds the
511 511 * ORIGINAL upload path, so the URL of a generated derivative
512 - * (`logo-512.png`) returns 0 — and that is exactly what the media picker
513 - * hands back when the user chooses a size. Strip the dimension suffix and
514 - * try the original once.
512 + * (`logo-512x512.png`) returns 0 — and that is exactly what the media
513 + * picker hands back when the user chooses a size. Attachment_Lookup falls
514 + * back to the original behind it; the fallback started here and moved
515 + * there when every other image lookup turned out to need it (#847).
515 516 *
516 517 * Shared with SEO_Manager's site-icon filter so both sides of the feature
517 518 * agree on which attachment a configured URL means.
518 519 *
@@ -521,21 +522,9 @@
521 522 * @param string $url Configured icon URL.
522 523 * @return int Attachment ID, or 0.
523 524 */
524 525 public static function icon_attachment_id(string $url): int {
525 - $attachment_id = (int) attachment_url_to_postid($url);
526 -
527 - if ($attachment_id) {
528 - return $attachment_id;
529 - }
530 -
531 - $original = preg_replace('/-\d+x\d+(?=\.[a-zA-Z0-9]+$)/', '', $url);
532 -
533 - if (is_string($original) && $original !== $url) {
534 - return (int) attachment_url_to_postid($original);
535 - }
536 -
537 - return 0;
526 + return Attachment_Lookup::id_from_url($url);
538 527 }
539 528
540 529 /**
541 530 * Which ICON_SIZES derivatives this attachment still needs.
@@ -1432,13 +1421,16 @@
1432 1421 }
1433 1422
1434 1423 // Additional logo analysis for local images
1435 1424 if (!empty($logo_url) && filter_var($logo_url, FILTER_VALIDATE_URL)) {
1436 - $attachment_id = attachment_url_to_postid($logo_url);
1425 + $attachment_id = Attachment_Lookup::id_from_url($logo_url);
1437 1426 if ($attachment_id) {
1438 1427 $image_meta = wp_get_attachment_metadata($attachment_id);
1439 - $width = isset($image_meta['width']) ? (int) $image_meta['width'] : 0;
1440 - $height = isset($image_meta['height']) ? (int) $image_meta['height'] : 0;
1428 + // The configured file's own size — a logo picked at a generated
1429 + // size is not as large as the upload behind it.
1430 + $logo_file = Attachment_Lookup::describe($attachment_id, $logo_url);
1431 + $width = $logo_file['width'];
1432 + $height = $logo_file['height'];
1441 1433
1442 1434 // SVG logos store 0x0 metadata — no dimension/ratio analysis
1443 1435 // is possible (and dividing by 0 is fatal).
1444 1436 if ($image_meta && $width > 0 && $height > 0) {
@@ -4261,18 +4253,20 @@
4261 4253 return $optimization;
4262 4254 }
4263 4255
4264 4256 // Check if it's a local image
4265 - $attachment_id = attachment_url_to_postid($value);
4257 + $attachment_id = Attachment_Lookup::id_from_url($value);
4266 4258 if ($attachment_id) {
4267 4259 $image_meta = wp_get_attachment_metadata($attachment_id);
4268 4260
4269 4261 if ($image_meta && isset($image_meta['width'], $image_meta['height'])) {
4270 - // Check recommended size
4262 + // Check recommended size, against the configured file itself
4263 + // rather than the upload it may have been generated from.
4271 4264 if (isset($config['recommended_size'])) {
4272 4265 [$rec_width, $rec_height] = explode('x', $config['recommended_size']);
4266 + $image_file = Attachment_Lookup::describe($attachment_id, $value);
4273 4267
4274 - if ((int) $image_meta['width'] !== (int) $rec_width || (int) $image_meta['height'] !== (int) $rec_height) {
4268 + if ($image_file['width'] !== (int) $rec_width || $image_file['height'] !== (int) $rec_height) {
4275 4269 $optimization['suggestions'][] = "Consider using {$config['recommended_size']} size for optimal {$element}";
4276 4270 }
4277 4271 }
4278 4272