← All changes
|
includes/diagnostics/class-foreign-schema-detector.php
+2
-33
2.14.1
→
2.14.0
View file →
| @@ -58,12 +58,11 @@ | ||
| 58 | 58 | * |
| 59 | 59 | * `class` matches a token in the script tag's class attribute, which is the |
| 60 | 60 | * strongest signal available — the big four each tag their own block. `comment` |
| 61 | 61 | * matches the HTML comment wrapper a plugin prints around its head output, |
| 62 | - * for the ones that carry no class. `id`, where present, matches the script | |
| 63 | - * tag's id attribute exactly, for a plugin that labels its block that way. | |
| 62 | + * for the ones that carry no class. | |
| 64 | 63 | * |
| 65 | - * @var array<string, array{name:string, class:string[], comment:string[], id?:string[]}> | |
| 64 | + * @var array<string, array{name:string, class:string[], comment:string[]}> | |
| 66 | 65 | */ |
| 67 | 66 | private const SIGNATURES = [ |
| 68 | 67 | 'yoast' => [ |
| 69 | 68 | 'name' => 'Yoast SEO', |
| @@ -99,16 +98,8 @@ | ||
| 99 | 98 | 'name' => 'WooCommerce', |
| 100 | 99 | 'class' => [], |
| 101 | 100 | 'comment' => ['woocommerce json-ld'], |
| 102 | 101 | ], |
| 103 | - // SureRank tags its block by id, not class, and prints it outside | |
| 104 | - // its "SureRank Meta Data" comment pair (#916). | |
| 105 | - 'surerank' => [ | |
| 106 | - 'name' => 'SureRank', | |
| 107 | - 'class' => [], | |
| 108 | - 'comment' => [], | |
| 109 | - 'id' => ['surerank-schema'], | |
| 110 | - ], | |
| 111 | 102 | ]; |
| 112 | 103 | |
| 113 | 104 | /** |
| 114 | 105 | * Schema types worth warning about when both sides publish one. |
| @@ -365,16 +356,11 @@ | ||
| 365 | 356 | * @return array{slug:string, name:string, guess:bool} |
| 366 | 357 | */ |
| 367 | 358 | private function attribute(array $block): array { |
| 368 | 359 | $classes = $this->class_tokens($block['tag']); |
| 369 | - $tag_id = $this->tag_id($block['tag']); | |
| 370 | 360 | $comment = strtolower($block['preceding']); |
| 371 | 361 | |
| 372 | 362 | foreach (self::SIGNATURES as $slug => $signature) { |
| 373 | - if ($tag_id !== '' && in_array($tag_id, $signature['id'] ?? [], true)) { | |
| 374 | - return ['slug' => $slug, 'name' => $signature['name'], 'guess' => false]; | |
| 375 | - } | |
| 376 | - | |
| 377 | 363 | foreach ($signature['class'] as $class) { |
| 378 | 364 | if (in_array($class, $classes, true)) { |
| 379 | 365 | return ['slug' => $slug, 'name' => $signature['name'], 'guess' => false]; |
| 380 | 366 | } |
| @@ -413,25 +399,8 @@ | ||
| 413 | 399 | $names[$slug] = (string) ($plugin['name'] ?? $slug); |
| 414 | 400 | } |
| 415 | 401 | |
| 416 | 402 | return $names; |
| 417 | - } | |
| 418 | - | |
| 419 | - /** | |
| 420 | - * The id attribute of a script tag, lowercased. | |
| 421 | - * | |
| 422 | - * @since 2.15.0 | |
| 423 | - * | |
| 424 | - * @param string $attributes Attribute text from the opening script tag. | |
| 425 | - * @return string Id, or an empty string when the tag has none. | |
| 426 | - */ | |
| 427 | - private function tag_id(string $attributes): string { | |
| 428 | - // Whitespace before the name, so `data-id` is not read as `id`. | |
| 429 | - if (!preg_match('#(?:^|\s)id\s*=\s*["\']([^"\']*)["\']#i', $attributes, $match)) { | |
| 430 | - return ''; | |
| 431 | - } | |
| 432 | - | |
| 433 | - return strtolower(trim($match[1])); | |
| 434 | 403 | } |
| 435 | 404 | |
| 436 | 405 | /** |
| 437 | 406 | * Class tokens on a script tag. |