| @@ -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 |
| @@ -1513,11 +1541,12 @@ | ||
| 1513 | 1541 | $optimization['score'] -= 15; |
| 1514 | 1542 | } |
| 1515 | 1543 | } |
| 1516 | 1544 | |
| 1517 | - // Business type validation | |
| 1518 | - if (empty($settings['business_type'])) { | |
| 1519 | - $optimization['suggestions'][] = 'Select a specific business type for better schema markup'; | |
| 1545 | + // Business type validation (shared rule, one message — #622). | |
| 1546 | + $business_type = $this->business_type_status($settings); | |
| 1547 | + if ('suggestion' === $business_type['status']) { | |
| 1548 | + $optimization['suggestions'][] = $business_type['message']; | |
| 1520 | 1549 | $optimization['score'] -= 5; |
| 1521 | 1550 | } |
| 1522 | 1551 | |
| 1523 | 1552 | // Email validation |
| @@ -2047,24 +2076,17 @@ | ||
| 2047 | 2076 | 'icon' => '✗' |
| 2048 | 2077 | ]; |
| 2049 | 2078 | } |
| 2050 | 2079 | |
| 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 | - } | |
| 2080 | + // Business Type validation — see business_type_status() for why there | |
| 2081 | + // is exactly one rule here now (#622). | |
| 2082 | + $business_type = $this->business_type_status($settings); | |
| 2083 | + $field_details[] = [ | |
| 2084 | + 'field' => 'business_type', | |
| 2085 | + 'label' => $business_type['message'], | |
| 2086 | + 'status' => $business_type['status'], | |
| 2087 | + 'icon' => 'valid' === $business_type['status'] ? '✓' : '⚠', | |
| 2088 | + ]; | |
| 2067 | 2089 | |
| 2068 | 2090 | // Address validation (NAP consistency) |
| 2069 | 2091 | $address_fields = ['business_address', 'business_city', 'business_state', 'business_country']; |
| 2070 | 2092 | $address_complete = true; |
| @@ -2748,11 +2770,15 @@ | ||
| 2748 | 2770 | } else { |
| 2749 | 2771 | $validation['suggestions'][] = 'Add business hours to improve local search visibility'; |
| 2750 | 2772 | } |
| 2751 | 2773 | |
| 2752 | - // Validate business type | |
| 2753 | - if (empty($settings['business_type'])) { | |
| 2754 | - $validation['suggestions'][] = 'Select a specific business type for better schema markup'; | |
| 2774 | + // Business type, through the shared rule (#622). This is the only place | |
| 2775 | + // it is reported on the generic path: validate_settings() with no tab | |
| 2776 | + // context attaches basic-info field details, not business-info ones, so | |
| 2777 | + // without this the setting would go unreported there entirely. | |
| 2778 | + $business_type = $this->business_type_status($settings); | |
| 2779 | + if ('suggestion' === $business_type['status']) { | |
| 2780 | + $validation['suggestions'][] = $business_type['message']; | |
| 2755 | 2781 | } |
| 2756 | 2782 | |
| 2757 | 2783 | return $validation; |
| 2758 | 2784 | } |
| @@ -2945,12 +2971,86 @@ | ||
| 2945 | 2971 | ? $sanitized['canonical_scheme'] |
| 2946 | 2972 | : Url_Scheme::AUTOMATIC; |
| 2947 | 2973 | } |
| 2948 | 2974 | |
| 2975 | + // Same reasoning again for the business type. It goes straight into | |
| 2976 | + // LocalBusiness schema, so a type that is not in the schema.org | |
| 2977 | + // vocabulary is invalid structured data — and storing it verbatim would | |
| 2978 | + // have get-site-identity-settings report a type the site cannot | |
| 2979 | + // actually publish. An empty value keeps meaning "not set"; anything | |
| 2980 | + // else unrecognised falls back to the general-purpose root (#623). | |
| 2981 | + if (array_key_exists('business_type', $sanitized)) { | |
| 2982 | + $type = (string) $sanitized['business_type']; | |
| 2983 | + | |
| 2984 | + if ('' !== $type && !\ThinkRank\Config\Local_Business_Types_Config::is_valid($type)) { | |
| 2985 | + $type = \ThinkRank\Config\Local_Business_Types_Config::ROOT; | |
| 2986 | + } | |
| 2987 | + | |
| 2988 | + $sanitized['business_type'] = $type; | |
| 2989 | + } | |
| 2990 | + | |
| 2949 | 2991 | return $sanitized; |
| 2950 | 2992 | } |
| 2951 | 2993 | |
| 2952 | 2994 | /** |
| 2995 | + * schema.org's general-purpose LocalBusiness type. | |
| 2996 | + * | |
| 2997 | + * The default, the first option in the control, and a valid answer in its | |
| 2998 | + * own right — which is the whole point of #622. | |
| 2999 | + * | |
| 3000 | + * @since 2.10.0 | |
| 3001 | + * @var string | |
| 3002 | + */ | |
| 3003 | + private const GENERAL_BUSINESS_TYPE = 'LocalBusiness'; | |
| 3004 | + | |
| 3005 | + /** | |
| 3006 | + * The one rule for whether a business type needs the user's attention. | |
| 3007 | + * | |
| 3008 | + * There were three, with two wordings and two different conditions. Two | |
| 3009 | + * fired when the value was empty; the third fired when it WAS | |
| 3010 | + * `LocalBusiness` — which is the default, the first option in the control | |
| 3011 | + * and a perfectly valid schema.org type. So the warning appeared out of the | |
| 3012 | + * box for every site, could not be cleared without choosing a type that | |
| 3013 | + * might be inaccurate, and on an empty value it appeared three times in two | |
| 3014 | + * different phrasings, which is why it was reported as showing twice (#622). | |
| 3015 | + * | |
| 3016 | + * The rule now: a type is expected, and any type in the vocabulary is a | |
| 3017 | + * correct answer. Only an unset value is worth prompting about. | |
| 3018 | + * `LocalBusiness` is the general-purpose answer and is accepted as one — | |
| 3019 | + * with a note that a more specific type sharpens the schema, phrased as the | |
| 3020 | + * guidance it is rather than as a fault the user has to clear. | |
| 3021 | + * | |
| 3022 | + * @since 2.10.0 | |
| 3023 | + * | |
| 3024 | + * @param array $settings Site identity settings. | |
| 3025 | + * @return array{status:string,message:string} `valid` or `suggestion`. | |
| 3026 | + */ | |
| 3027 | + private function business_type_status(array $settings): array { | |
| 3028 | + $type = trim((string) ($settings['business_type'] ?? '')); | |
| 3029 | + | |
| 3030 | + if ('' === $type) { | |
| 3031 | + return [ | |
| 3032 | + 'status' => 'suggestion', | |
| 3033 | + 'message' => __('Select a business type so your local schema describes the right kind of business.', 'thinkrank'), | |
| 3034 | + ]; | |
| 3035 | + } | |
| 3036 | + | |
| 3037 | + // The literal rather than a constant from the expanded type list (#623): | |
| 3038 | + // that lands on its own branch, and this fix must not wait on it. | |
| 3039 | + if (self::GENERAL_BUSINESS_TYPE === $type) { | |
| 3040 | + return [ | |
| 3041 | + 'status' => 'valid', | |
| 3042 | + 'message' => __('Business type is set to Local Business. A more specific type sharpens your schema, if one fits.', 'thinkrank'), | |
| 3043 | + ]; | |
| 3044 | + } | |
| 3045 | + | |
| 3046 | + return [ | |
| 3047 | + 'status' => 'valid', | |
| 3048 | + 'message' => __('Business type is selected for proper schema markup.', 'thinkrank'), | |
| 3049 | + ]; | |
| 3050 | + } | |
| 3051 | + | |
| 3052 | + /** | |
| 2953 | 3053 | * Get default settings for a context type (implements interface) |
| 2954 | 3054 | * |
| 2955 | 3055 | * @since 1.0.0 |
| 2956 | 3056 | * |
| @@ -3675,9 +3775,22 @@ | ||
| 3675 | 3775 | // business sitemap and the sitemaps other plugins register both land |
| 3676 | 3776 | // here for the same reason, so they go through one list (#104). |
| 3677 | 3777 | $extra = []; |
| 3678 | 3778 | |
| 3679 | - if (file_exists(ABSPATH . 'local-sitemap.xml')) { | |
| 3779 | + // Not a file test. Under dynamic delivery the local sitemap is | |
| 3780 | + // served from PHP and no file is ever written, so file_exists() | |
| 3781 | + // silently dropped a sitemap the site really does publish (#752). | |
| 3782 | + // On static sites the file is still what proves it, so both count. | |
| 3783 | + $local_sitemap_published = file_exists(ABSPATH . 'local-sitemap.xml'); | |
| 3784 | + | |
| 3785 | + if (!$local_sitemap_published && class_exists('ThinkRank\\SEO\\Sitemap_Generator')) { | |
| 3786 | + $generator = new \ThinkRank\SEO\Sitemap_Generator(false); | |
| 3787 | + | |
| 3788 | + $local_sitemap_published = 'dynamic' === $generator->resolve_delivery_mode() | |
| 3789 | + && $generator->publishes_local_sitemap(); | |
| 3790 | + } | |
| 3791 | + | |
| 3792 | + if ($local_sitemap_published) { | |
| 3680 | 3793 | $extra[] = '/local-sitemap.xml'; |
| 3681 | 3794 | } |
| 3682 | 3795 | |
| 3683 | 3796 | foreach (\ThinkRank\SEO\Sitemap_Generator::additional_sitemaps() as $path) { |