| @@ -40,8 +40,36 @@ | ||
| 40 | 40 | */ |
| 41 | 41 | class Site_Identity_Manager extends Abstract_SEO_Manager { |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | + * The per-context title formats as ThinkRank ships them. | |
| 45 | + * | |
| 46 | + * These are not in get_default_settings(): the admin screen seeds them on | |
| 47 | + * first save, so on a real install they are stored values, indistinguishable | |
| 48 | + * from a template the user typed. The migration needs to tell those two | |
| 49 | + * apart — it may overwrite a shipped default with an imported template, and | |
| 50 | + * must never overwrite a choice the user made — so this is the record of | |
| 51 | + * what "untouched" looks like. | |
| 52 | + * | |
| 53 | + * Keep in step with getDefaultSettings() in | |
| 54 | + * src/admin/components/essential-seo/SiteIdentityTab.js. SiteIdentityTitleFormatDefaultsTest | |
| 55 | + * fails when the two drift. | |
| 56 | + * | |
| 57 | + * @since 2.8.0 | |
| 58 | + * @var array<string, string> | |
| 59 | + */ | |
| 60 | + public const TITLE_FORMAT_DEFAULTS = [ | |
| 61 | + 'homepage_title' => '%site_title% %sep% %site_description%', | |
| 62 | + 'post_title' => '%post_title% %sep% %site_title%', | |
| 63 | + 'page_title' => '%page_title% %sep% %site_title%', | |
| 64 | + 'category_title' => '%category_title% %sep% %site_title%', | |
| 65 | + 'tag_title' => '%tag_title% %sep% %site_title%', | |
| 66 | + 'author_title' => '%author_name% %sep% %site_title%', | |
| 67 | + 'search_title' => 'Search Results for "%search_term%" %sep% %site_title%', | |
| 68 | + 'archive_title' => '%archive_title% %sep% %site_title%', | |
| 69 | + ]; | |
| 70 | + | |
| 71 | + /** | |
| 44 | 72 | * WordPress filesystem instance |
| 45 | 73 | * |
| 46 | 74 | * @since 1.0.0 |
| 47 | 75 | * @var \WP_Filesystem_Base|null |
| @@ -290,8 +318,24 @@ | ||
| 290 | 318 | * @var bool |
| 291 | 319 | */ |
| 292 | 320 | private static bool $icon_sizes_listener_registered = false; |
| 293 | 321 | |
| 322 | + /** | |
| 323 | + * Whether the robots.txt resync listener is registered for this request. | |
| 324 | + * | |
| 325 | + * @since 2.14.0 | |
| 326 | + * @var bool | |
| 327 | + */ | |
| 328 | + private static bool $robots_sync_listener_registered = false; | |
| 329 | + | |
| 330 | + /** | |
| 331 | + * Flag set when a plugin change may have altered the sitemap set. | |
| 332 | + * | |
| 333 | + * @since 2.14.0 | |
| 334 | + * @var string | |
| 335 | + */ | |
| 336 | + public const ROBOTS_RESYNC_OPTION = 'thinkrank_robots_txt_resync_pending'; | |
| 337 | + | |
| 294 | 338 | public function __construct() { |
| 295 | 339 | parent::__construct('site_identity'); |
| 296 | 340 | |
| 297 | 341 | if (!self::$icon_sizes_listener_registered) { |
| @@ -300,11 +344,72 @@ | ||
| 300 | 344 | // Admin only: resizing is not front-end work, and admin traffic is |
| 301 | 345 | // enough to run a one-time backfill promptly. |
| 302 | 346 | add_action('admin_init', [self::class, 'maybe_backfill_icon_sizes']); |
| 303 | 347 | } |
| 348 | + | |
| 349 | + if (!self::$robots_sync_listener_registered) { | |
| 350 | + self::$robots_sync_listener_registered = true; | |
| 351 | + | |
| 352 | + // A physical robots.txt bypasses PHP entirely, so composing the | |
| 353 | + // Sitemap block at render time fixes the served output only on | |
| 354 | + // sites with no file. Activating or deactivating a sitemap | |
| 355 | + // contributor changes the set, and until #835 nothing rewrote the | |
| 356 | + // file: the deactivated plugin's sitemap stayed advertised, serving | |
| 357 | + // HTML to anything that followed it. | |
| 358 | + add_action('activated_plugin', [self::class, 'flag_robots_txt_resync']); | |
| 359 | + add_action('deactivated_plugin', [self::class, 'flag_robots_txt_resync']); | |
| 360 | + add_action('init', [self::class, 'maybe_resync_robots_txt'], 99); | |
| 361 | + } | |
| 304 | 362 | } |
| 305 | 363 | |
| 306 | 364 | /** |
| 365 | + * Note that the set of sitemap contributors may have changed. | |
| 366 | + * | |
| 367 | + * Deliberately unconditional about which plugin: a contributor is anything | |
| 368 | + * hooking `thinkrank_additional_sitemaps`, which is resolved at runtime and | |
| 369 | + * cannot be inspected for a plugin that is on its way out. | |
| 370 | + * | |
| 371 | + * The rewrite is not done here. `deactivated_plugin` fires inside the | |
| 372 | + * request that deactivated it, while that plugin's filters are still | |
| 373 | + * attached, so rendering now still sees the sitemap that is going away — | |
| 374 | + * measured, not assumed: the first version of this fix wrote the | |
| 375 | + * deactivated plugin's sitemap straight back into the file. The next | |
| 376 | + * request has the real plugin set loaded, so the work waits for it. | |
| 377 | + * | |
| 378 | + * @since 2.14.0 | |
| 379 | + * @return void | |
| 380 | + */ | |
| 381 | + public static function flag_robots_txt_resync(): void { | |
| 382 | + if (!file_exists(ABSPATH . 'robots.txt')) { | |
| 383 | + return; | |
| 384 | + } | |
| 385 | + | |
| 386 | + update_option(self::ROBOTS_RESYNC_OPTION, 1, false); | |
| 387 | + } | |
| 388 | + | |
| 389 | + /** | |
| 390 | + * Rewrite the physical robots.txt once, on the request after a change. | |
| 391 | + * | |
| 392 | + * @since 2.14.0 | |
| 393 | + * @return void | |
| 394 | + */ | |
| 395 | + public static function maybe_resync_robots_txt(): void { | |
| 396 | + if (!get_option(self::ROBOTS_RESYNC_OPTION)) { | |
| 397 | + return; | |
| 398 | + } | |
| 399 | + | |
| 400 | + // Cleared first, so a render that fatals cannot retry on every request | |
| 401 | + // for the rest of the site's life. | |
| 402 | + delete_option(self::ROBOTS_RESYNC_OPTION); | |
| 403 | + | |
| 404 | + if (!file_exists(ABSPATH . 'robots.txt')) { | |
| 405 | + return; | |
| 406 | + } | |
| 407 | + | |
| 408 | + (new self())->sync_robots_txt_file(); | |
| 409 | + } | |
| 410 | + | |
| 411 | + /** | |
| 307 | 412 | * Save settings, then refresh what a new canonical scheme invalidates. |
| 308 | 413 | * |
| 309 | 414 | * The static sitemap files are written with the scheme in force when they |
| 310 | 415 | * were built, and nothing else rebuilds them until a post or term changes. |
| @@ -480,11 +585,12 @@ | ||
| 480 | 585 | * Attachment ID behind a configured icon URL, or 0 when it is not ours. |
| 481 | 586 | * |
| 482 | 587 | * attachment_url_to_postid() matches _wp_attached_file, which holds the |
| 483 | 588 | * ORIGINAL upload path, so the URL of a generated derivative |
| 484 | - * (`logo-512.png`) returns 0 — and that is exactly what the media picker | |
| 485 | - * hands back when the user chooses a size. Strip the dimension suffix and | |
| 486 | - * try the original once. | |
| 589 | + * (`logo-512x512.png`) returns 0 — and that is exactly what the media | |
| 590 | + * picker hands back when the user chooses a size. Attachment_Lookup falls | |
| 591 | + * back to the original behind it; the fallback started here and moved | |
| 592 | + * there when every other image lookup turned out to need it (#847). | |
| 487 | 593 | * |
| 488 | 594 | * Shared with SEO_Manager's site-icon filter so both sides of the feature |
| 489 | 595 | * agree on which attachment a configured URL means. |
| 490 | 596 | * |
| @@ -493,21 +599,9 @@ | ||
| 493 | 599 | * @param string $url Configured icon URL. |
| 494 | 600 | * @return int Attachment ID, or 0. |
| 495 | 601 | */ |
| 496 | 602 | public static function icon_attachment_id(string $url): int { |
| 497 | - $attachment_id = (int) attachment_url_to_postid($url); | |
| 498 | - | |
| 499 | - if ($attachment_id) { | |
| 500 | - return $attachment_id; | |
| 501 | - } | |
| 502 | - | |
| 503 | - $original = preg_replace('/-\d+x\d+(?=\.[a-zA-Z0-9]+$)/', '', $url); | |
| 504 | - | |
| 505 | - if (is_string($original) && $original !== $url) { | |
| 506 | - return (int) attachment_url_to_postid($original); | |
| 507 | - } | |
| 508 | - | |
| 509 | - return 0; | |
| 603 | + return Attachment_Lookup::id_from_url($url); | |
| 510 | 604 | } |
| 511 | 605 | |
| 512 | 606 | /** |
| 513 | 607 | * Which ICON_SIZES derivatives this attachment still needs. |
| @@ -797,9 +891,20 @@ | ||
| 797 | 891 | // here rather than stored: the textarea holds the user's body, with |
| 798 | 892 | // the fenced block stripped out of every read and re-applied on every |
| 799 | 893 | // render. A site-wide block already disallows everyone, so adding the |
| 800 | 894 | // per-agent group there would be noise restating the same refusal. |
| 895 | + // Composed here rather than read from storage, for the same reason as | |
| 896 | + // the AI block below: the set of sitemaps an install publishes is a | |
| 897 | + // runtime fact. `robots_txt_content` is a snapshot of it taken at the | |
| 898 | + // last save, and nothing invalidated that snapshot, so deactivating a | |
| 899 | + // sitemap provider left its URL advertised and serving HTML (#835). | |
| 900 | + // Composing it on every render means the advertisement agrees with what | |
| 901 | + // the install publishes, in both directions, with no cache to expire. | |
| 801 | 902 | if (!$fully_blocked) { |
| 903 | + $body = $this->apply_sitemap_block($body); | |
| 904 | + } | |
| 905 | + | |
| 906 | + if (!$fully_blocked) { | |
| 802 | 907 | $body = $this->apply_ai_crawler_block($body, $settings); |
| 803 | 908 | } |
| 804 | 909 | |
| 805 | 910 | if ($body === '') { |
| @@ -809,8 +914,87 @@ | ||
| 809 | 914 | return $this->robots_txt_header() . $body . "\n"; |
| 810 | 915 | } |
| 811 | 916 | |
| 812 | 917 | /** |
| 918 | + * Replace the generated Sitemap block with the one this install publishes. | |
| 919 | + * | |
| 920 | + * @since 2.14.0 | |
| 921 | + * @param string $body Robots.txt body, without the header. | |
| 922 | + * @return string | |
| 923 | + */ | |
| 924 | + private function apply_sitemap_block(string $body): string { | |
| 925 | + $stripped = $this->strip_generated_sitemap_block($body); | |
| 926 | + $urls = $this->get_sitemap_urls_for_robots(); | |
| 927 | + | |
| 928 | + if (empty($urls)) { | |
| 929 | + return $stripped; | |
| 930 | + } | |
| 931 | + | |
| 932 | + $block = ''; | |
| 933 | + foreach ($urls as $url) { | |
| 934 | + $block .= 'Sitemap: ' . $url . "\n"; | |
| 935 | + } | |
| 936 | + | |
| 937 | + if ('' === trim($stripped)) { | |
| 938 | + return trim($block); | |
| 939 | + } | |
| 940 | + | |
| 941 | + // The grammar build_robots_txt_content() writes: one blank line before | |
| 942 | + // the block, none inside it. A blank line terminates a record in the | |
| 943 | + // robots.txt grammar, so a line between every directive is invalid. | |
| 944 | + return rtrim($stripped) . "\n\n" . trim($block); | |
| 945 | + } | |
| 946 | + | |
| 947 | + /** | |
| 948 | + * Remove the plugin-written Sitemap block from a stored body. | |
| 949 | + * | |
| 950 | + * Only the trailing run of `Sitemap:` lines is removed, which is the exact | |
| 951 | + * shape `build_robots_txt_content()` writes: a blank line, then nothing but | |
| 952 | + * `Sitemap:` lines to the end of the body. A `Sitemap:` line anywhere else | |
| 953 | + * was typed by the site owner and is left exactly where they put it, which | |
| 954 | + * is why this cannot simply strip every matching line. | |
| 955 | + * | |
| 956 | + * @since 2.14.0 | |
| 957 | + * @param string $body Robots.txt body. | |
| 958 | + * @return string | |
| 959 | + */ | |
| 960 | + private function strip_generated_sitemap_block(string $body): string { | |
| 961 | + $lines = preg_split('/\R/', $body); | |
| 962 | + | |
| 963 | + if (!is_array($lines)) { | |
| 964 | + return $body; | |
| 965 | + } | |
| 966 | + | |
| 967 | + $cut = count($lines); | |
| 968 | + | |
| 969 | + // Walk back over the trailing block: sitemap lines, and the blank lines | |
| 970 | + // that separate or pad it. Anything else ends the block. | |
| 971 | + for ($i = count($lines) - 1; $i >= 0; $i--) { | |
| 972 | + $line = trim($lines[$i]); | |
| 973 | + | |
| 974 | + if ('' === $line) { | |
| 975 | + $cut = $i; | |
| 976 | + continue; | |
| 977 | + } | |
| 978 | + | |
| 979 | + if (0 === stripos($line, 'sitemap:')) { | |
| 980 | + $cut = $i; | |
| 981 | + continue; | |
| 982 | + } | |
| 983 | + | |
| 984 | + break; | |
| 985 | + } | |
| 986 | + | |
| 987 | + if ($cut >= count($lines)) { | |
| 988 | + return $body; | |
| 989 | + } | |
| 990 | + | |
| 991 | + // Nothing but sitemap lines in the whole body means there is no owner | |
| 992 | + // content to keep. | |
| 993 | + return rtrim(implode("\n", array_slice($lines, 0, $cut))); | |
| 994 | + } | |
| 995 | + | |
| 996 | + /** | |
| 813 | 997 | * Resolve the robots.txt actually served to crawlers, with its origin. |
| 814 | 998 | * |
| 815 | 999 | * Lets an API/MCP consumer see the effective output without crawling the |
| 816 | 1000 | * URL. Mirrors serving precedence: a physical robots.txt in the web root is |
| @@ -1404,13 +1588,16 @@ | ||
| 1404 | 1588 | } |
| 1405 | 1589 | |
| 1406 | 1590 | // Additional logo analysis for local images |
| 1407 | 1591 | if (!empty($logo_url) && filter_var($logo_url, FILTER_VALIDATE_URL)) { |
| 1408 | - $attachment_id = attachment_url_to_postid($logo_url); | |
| 1592 | + $attachment_id = Attachment_Lookup::id_from_url($logo_url); | |
| 1409 | 1593 | if ($attachment_id) { |
| 1410 | 1594 | $image_meta = wp_get_attachment_metadata($attachment_id); |
| 1411 | - $width = isset($image_meta['width']) ? (int) $image_meta['width'] : 0; | |
| 1412 | - $height = isset($image_meta['height']) ? (int) $image_meta['height'] : 0; | |
| 1595 | + // The configured file's own size — a logo picked at a generated | |
| 1596 | + // size is not as large as the upload behind it. | |
| 1597 | + $logo_file = Attachment_Lookup::describe($attachment_id, $logo_url); | |
| 1598 | + $width = $logo_file['width']; | |
| 1599 | + $height = $logo_file['height']; | |
| 1413 | 1600 | |
| 1414 | 1601 | // SVG logos store 0x0 metadata — no dimension/ratio analysis |
| 1415 | 1602 | // is possible (and dividing by 0 is fatal). |
| 1416 | 1603 | if ($image_meta && $width > 0 && $height > 0) { |
| @@ -1513,11 +1700,12 @@ | ||
| 1513 | 1700 | $optimization['score'] -= 15; |
| 1514 | 1701 | } |
| 1515 | 1702 | } |
| 1516 | 1703 | |
| 1517 | - // Business type validation | |
| 1518 | - if (empty($settings['business_type'])) { | |
| 1519 | - $optimization['suggestions'][] = 'Select a specific business type for better schema markup'; | |
| 1704 | + // Business type validation (shared rule, one message — #622). | |
| 1705 | + $business_type = $this->business_type_status($settings); | |
| 1706 | + if ('suggestion' === $business_type['status']) { | |
| 1707 | + $optimization['suggestions'][] = $business_type['message']; | |
| 1520 | 1708 | $optimization['score'] -= 5; |
| 1521 | 1709 | } |
| 1522 | 1710 | |
| 1523 | 1711 | // Email validation |
| @@ -2047,24 +2235,17 @@ | ||
| 2047 | 2235 | 'icon' => '✗' |
| 2048 | 2236 | ]; |
| 2049 | 2237 | } |
| 2050 | 2238 | |
| 2051 | - // Business Type validation | |
| 2052 | - if (!empty($settings['business_type']) && $settings['business_type'] !== 'LocalBusiness') { | |
| 2053 | - $field_details[] = [ | |
| 2054 | - 'field' => 'business_type', | |
| 2055 | - 'label' => 'Business type is selected for proper schema markup.', | |
| 2056 | - 'status' => 'valid', | |
| 2057 | - 'icon' => '✓' | |
| 2058 | - ]; | |
| 2059 | - } else { | |
| 2060 | - $field_details[] = [ | |
| 2061 | - 'field' => 'business_type', | |
| 2062 | - 'label' => 'Specific business type selection recommended for better schema markup.', | |
| 2063 | - 'status' => 'suggestion', | |
| 2064 | - 'icon' => '⚠' | |
| 2065 | - ]; | |
| 2066 | - } | |
| 2239 | + // Business Type validation — see business_type_status() for why there | |
| 2240 | + // is exactly one rule here now (#622). | |
| 2241 | + $business_type = $this->business_type_status($settings); | |
| 2242 | + $field_details[] = [ | |
| 2243 | + 'field' => 'business_type', | |
| 2244 | + 'label' => $business_type['message'], | |
| 2245 | + 'status' => $business_type['status'], | |
| 2246 | + 'icon' => 'valid' === $business_type['status'] ? '✓' : '⚠', | |
| 2247 | + ]; | |
| 2067 | 2248 | |
| 2068 | 2249 | // Address validation (NAP consistency) |
| 2069 | 2250 | $address_fields = ['business_address', 'business_city', 'business_state', 'business_country']; |
| 2070 | 2251 | $address_complete = true; |
| @@ -2748,11 +2929,15 @@ | ||
| 2748 | 2929 | } else { |
| 2749 | 2930 | $validation['suggestions'][] = 'Add business hours to improve local search visibility'; |
| 2750 | 2931 | } |
| 2751 | 2932 | |
| 2752 | - // Validate business type | |
| 2753 | - if (empty($settings['business_type'])) { | |
| 2754 | - $validation['suggestions'][] = 'Select a specific business type for better schema markup'; | |
| 2933 | + // Business type, through the shared rule (#622). This is the only place | |
| 2934 | + // it is reported on the generic path: validate_settings() with no tab | |
| 2935 | + // context attaches basic-info field details, not business-info ones, so | |
| 2936 | + // without this the setting would go unreported there entirely. | |
| 2937 | + $business_type = $this->business_type_status($settings); | |
| 2938 | + if ('suggestion' === $business_type['status']) { | |
| 2939 | + $validation['suggestions'][] = $business_type['message']; | |
| 2755 | 2940 | } |
| 2756 | 2941 | |
| 2757 | 2942 | return $validation; |
| 2758 | 2943 | } |
| @@ -2888,8 +3073,10 @@ | ||
| 2888 | 3073 | return [ |
| 2889 | 3074 | // Title formats, one per context. |
| 2890 | 3075 | 'homepage_title', 'post_title', 'page_title', 'category_title', |
| 2891 | 3076 | 'tag_title', 'author_title', 'search_title', 'archive_title', |
| 3077 | + // The blog-index homepage's meta description (#897). | |
| 3078 | + 'homepage_description', | |
| 2892 | 3079 | // Breadcrumbs. |
| 2893 | 3080 | 'breadcrumb_prefix', 'show_current_page', 'breadcrumb_use_seo_title', |
| 2894 | 3081 | // Identity, as written by the setup wizard and the importers. |
| 2895 | 3082 | 'alternate_name', 'identity_type', 'represents', |
| @@ -2945,12 +3132,86 @@ | ||
| 2945 | 3132 | ? $sanitized['canonical_scheme'] |
| 2946 | 3133 | : Url_Scheme::AUTOMATIC; |
| 2947 | 3134 | } |
| 2948 | 3135 | |
| 3136 | + // Same reasoning again for the business type. It goes straight into | |
| 3137 | + // LocalBusiness schema, so a type that is not in the schema.org | |
| 3138 | + // vocabulary is invalid structured data — and storing it verbatim would | |
| 3139 | + // have get-site-identity-settings report a type the site cannot | |
| 3140 | + // actually publish. An empty value keeps meaning "not set"; anything | |
| 3141 | + // else unrecognised falls back to the general-purpose root (#623). | |
| 3142 | + if (array_key_exists('business_type', $sanitized)) { | |
| 3143 | + $type = (string) $sanitized['business_type']; | |
| 3144 | + | |
| 3145 | + if ('' !== $type && !\ThinkRank\Config\Local_Business_Types_Config::is_valid($type)) { | |
| 3146 | + $type = \ThinkRank\Config\Local_Business_Types_Config::ROOT; | |
| 3147 | + } | |
| 3148 | + | |
| 3149 | + $sanitized['business_type'] = $type; | |
| 3150 | + } | |
| 3151 | + | |
| 2949 | 3152 | return $sanitized; |
| 2950 | 3153 | } |
| 2951 | 3154 | |
| 2952 | 3155 | /** |
| 3156 | + * schema.org's general-purpose LocalBusiness type. | |
| 3157 | + * | |
| 3158 | + * The default, the first option in the control, and a valid answer in its | |
| 3159 | + * own right — which is the whole point of #622. | |
| 3160 | + * | |
| 3161 | + * @since 2.10.0 | |
| 3162 | + * @var string | |
| 3163 | + */ | |
| 3164 | + private const GENERAL_BUSINESS_TYPE = 'LocalBusiness'; | |
| 3165 | + | |
| 3166 | + /** | |
| 3167 | + * The one rule for whether a business type needs the user's attention. | |
| 3168 | + * | |
| 3169 | + * There were three, with two wordings and two different conditions. Two | |
| 3170 | + * fired when the value was empty; the third fired when it WAS | |
| 3171 | + * `LocalBusiness` — which is the default, the first option in the control | |
| 3172 | + * and a perfectly valid schema.org type. So the warning appeared out of the | |
| 3173 | + * box for every site, could not be cleared without choosing a type that | |
| 3174 | + * might be inaccurate, and on an empty value it appeared three times in two | |
| 3175 | + * different phrasings, which is why it was reported as showing twice (#622). | |
| 3176 | + * | |
| 3177 | + * The rule now: a type is expected, and any type in the vocabulary is a | |
| 3178 | + * correct answer. Only an unset value is worth prompting about. | |
| 3179 | + * `LocalBusiness` is the general-purpose answer and is accepted as one — | |
| 3180 | + * with a note that a more specific type sharpens the schema, phrased as the | |
| 3181 | + * guidance it is rather than as a fault the user has to clear. | |
| 3182 | + * | |
| 3183 | + * @since 2.10.0 | |
| 3184 | + * | |
| 3185 | + * @param array $settings Site identity settings. | |
| 3186 | + * @return array{status:string,message:string} `valid` or `suggestion`. | |
| 3187 | + */ | |
| 3188 | + private function business_type_status(array $settings): array { | |
| 3189 | + $type = trim((string) ($settings['business_type'] ?? '')); | |
| 3190 | + | |
| 3191 | + if ('' === $type) { | |
| 3192 | + return [ | |
| 3193 | + 'status' => 'suggestion', | |
| 3194 | + 'message' => __('Select a business type so your local schema describes the right kind of business.', 'thinkrank'), | |
| 3195 | + ]; | |
| 3196 | + } | |
| 3197 | + | |
| 3198 | + // The literal rather than a constant from the expanded type list (#623): | |
| 3199 | + // that lands on its own branch, and this fix must not wait on it. | |
| 3200 | + if (self::GENERAL_BUSINESS_TYPE === $type) { | |
| 3201 | + return [ | |
| 3202 | + 'status' => 'valid', | |
| 3203 | + 'message' => __('Business type is set to Local Business. A more specific type sharpens your schema, if one fits.', 'thinkrank'), | |
| 3204 | + ]; | |
| 3205 | + } | |
| 3206 | + | |
| 3207 | + return [ | |
| 3208 | + 'status' => 'valid', | |
| 3209 | + 'message' => __('Business type is selected for proper schema markup.', 'thinkrank'), | |
| 3210 | + ]; | |
| 3211 | + } | |
| 3212 | + | |
| 3213 | + /** | |
| 2953 | 3214 | * Get default settings for a context type (implements interface) |
| 2954 | 3215 | * |
| 2955 | 3216 | * @since 1.0.0 |
| 2956 | 3217 | * |
| @@ -3659,11 +3920,29 @@ | ||
| 3659 | 3920 | } |
| 3660 | 3921 | } |
| 3661 | 3922 | |
| 3662 | 3923 | if ($index_url !== '') { |
| 3663 | - // The index alone — it covers the children and, on a segmented | |
| 3664 | - // install, the local business sitemap too. | |
| 3665 | - return [$index_url]; | |
| 3924 | + // The index covers the children and, on a segmented install, | |
| 3925 | + // the local business sitemap too. | |
| 3926 | + // | |
| 3927 | + // It does not cover a sitemap contributed through | |
| 3928 | + // `thinkrank_additional_sitemaps`: the index is built by this | |
| 3929 | + // plugin's own generator and never lists them. Returning the | |
| 3930 | + // index alone therefore left a contributed sitemap with no | |
| 3931 | + // discovery path at all — absent from robots.txt and absent | |
| 3932 | + // from the index — so Pro's News sitemap was unreachable on any | |
| 3933 | + // install with the index enabled, which is the default (#835). | |
| 3934 | + $contributed = []; | |
| 3935 | + | |
| 3936 | + foreach (\ThinkRank\SEO\Sitemap_Generator::additional_sitemaps() as $path) { | |
| 3937 | + $url = home_url($path); | |
| 3938 | + | |
| 3939 | + if ($url !== $index_url && !in_array($url, $contributed, true)) { | |
| 3940 | + $contributed[] = $url; | |
| 3941 | + } | |
| 3942 | + } | |
| 3943 | + | |
| 3944 | + return array_merge([$index_url], $contributed); | |
| 3666 | 3945 | } |
| 3667 | 3946 | |
| 3668 | 3947 | // Fallback to default if no URLs found |
| 3669 | 3948 | if (empty($sitemap_urls)) { |
| @@ -3675,9 +3954,22 @@ | ||
| 3675 | 3954 | // business sitemap and the sitemaps other plugins register both land |
| 3676 | 3955 | // here for the same reason, so they go through one list (#104). |
| 3677 | 3956 | $extra = []; |
| 3678 | 3957 | |
| 3679 | - if (file_exists(ABSPATH . 'local-sitemap.xml')) { | |
| 3958 | + // Not a file test. Under dynamic delivery the local sitemap is | |
| 3959 | + // served from PHP and no file is ever written, so file_exists() | |
| 3960 | + // silently dropped a sitemap the site really does publish (#752). | |
| 3961 | + // On static sites the file is still what proves it, so both count. | |
| 3962 | + $local_sitemap_published = file_exists(ABSPATH . 'local-sitemap.xml'); | |
| 3963 | + | |
| 3964 | + if (!$local_sitemap_published && class_exists('ThinkRank\\SEO\\Sitemap_Generator')) { | |
| 3965 | + $generator = new \ThinkRank\SEO\Sitemap_Generator(false); | |
| 3966 | + | |
| 3967 | + $local_sitemap_published = 'dynamic' === $generator->resolve_delivery_mode() | |
| 3968 | + && $generator->publishes_local_sitemap(); | |
| 3969 | + } | |
| 3970 | + | |
| 3971 | + if ($local_sitemap_published) { | |
| 3680 | 3972 | $extra[] = '/local-sitemap.xml'; |
| 3681 | 3973 | } |
| 3682 | 3974 | |
| 3683 | 3975 | foreach (\ThinkRank\SEO\Sitemap_Generator::additional_sitemaps() as $path) { |
| @@ -4148,18 +4440,20 @@ | ||
| 4148 | 4440 | return $optimization; |
| 4149 | 4441 | } |
| 4150 | 4442 | |
| 4151 | 4443 | // Check if it's a local image |
| 4152 | - $attachment_id = attachment_url_to_postid($value); | |
| 4444 | + $attachment_id = Attachment_Lookup::id_from_url($value); | |
| 4153 | 4445 | if ($attachment_id) { |
| 4154 | 4446 | $image_meta = wp_get_attachment_metadata($attachment_id); |
| 4155 | 4447 | |
| 4156 | 4448 | if ($image_meta && isset($image_meta['width'], $image_meta['height'])) { |
| 4157 | - // Check recommended size | |
| 4449 | + // Check recommended size, against the configured file itself | |
| 4450 | + // rather than the upload it may have been generated from. | |
| 4158 | 4451 | if (isset($config['recommended_size'])) { |
| 4159 | 4452 | [$rec_width, $rec_height] = explode('x', $config['recommended_size']); |
| 4453 | + $image_file = Attachment_Lookup::describe($attachment_id, $value); | |
| 4160 | 4454 | |
| 4161 | - if ((int) $image_meta['width'] !== (int) $rec_width || (int) $image_meta['height'] !== (int) $rec_height) { | |
| 4455 | + if ($image_file['width'] !== (int) $rec_width || $image_file['height'] !== (int) $rec_height) { | |
| 4162 | 4456 | $optimization['suggestions'][] = "Consider using {$config['recommended_size']} size for optimal {$element}"; |
| 4163 | 4457 | } |
| 4164 | 4458 | } |
| 4165 | 4459 | |