← All changes
|
includes/frontend/class-global-seo-schema-output.php
+31
-0
2.4.0
→
2.9.0
View file →
| @@ -104,8 +104,22 @@ | ||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $settings = $this->get_global_seo_settings($post_type); |
| 107 | 107 | if (($settings['schema_type'] ?? '') === 'Product') { |
| 108 | + // ...but only if this class is actually going to emit it. The | |
| 109 | + // per-content-type Schema switch (#660) makes | |
| 110 | + // output_global_seo_schema() return before it builds anything, so | |
| 111 | + // claiming the entity here as well left the page with NO product | |
| 112 | + // structured data at all — strictly worse than the duplicate this | |
| 113 | + // method exists to prevent, and the opposite of what the docblock | |
| 114 | + // above promises for "ThinkRank's product schema disabled". | |
| 115 | + if (!\ThinkRank\SEO\Content_Type_Settings::is_enabled_for_current( | |
| 116 | + \ThinkRank\SEO\Content_Type_Settings::FEATURE_SCHEMA, | |
| 117 | + true | |
| 118 | + )) { | |
| 119 | + return $markup; | |
| 120 | + } | |
| 121 | + | |
| 108 | 122 | return []; |
| 109 | 123 | } |
| 110 | 124 | |
| 111 | 125 | // A per-post DEPLOYED Product schema duplicates WooCommerce's markup |
| @@ -153,8 +167,17 @@ | ||
| 153 | 167 | * @since 1.0.0 |
| 154 | 168 | * @return void |
| 155 | 169 | */ |
| 156 | 170 | public function output_global_seo_schema(): void { |
| 171 | + // Per-content-type schema switch. 'inherit' (the default) keeps schema | |
| 172 | + // on, exactly as before the matrix existed (#660). | |
| 173 | + if (!\ThinkRank\SEO\Content_Type_Settings::is_enabled_for_current( | |
| 174 | + \ThinkRank\SEO\Content_Type_Settings::FEATURE_SCHEMA, | |
| 175 | + true | |
| 176 | + )) { | |
| 177 | + return; | |
| 178 | + } | |
| 179 | + | |
| 157 | 180 | // Archives get a CollectionPage schema instead of the per-post-type one |
| 158 | 181 | if (!is_singular()) { |
| 159 | 182 | $this->output_archive_schema(); |
| 160 | 183 | return; |
| @@ -327,8 +350,16 @@ | ||
| 327 | 350 | * @param string $post_type Post type slug. |
| 328 | 351 | * @return bool True when structured data would be output for this post type. |
| 329 | 352 | */ |
| 330 | 353 | public function would_output_schema(string $post_type): bool { |
| 354 | + if (!\ThinkRank\SEO\Content_Type_Settings::is_enabled( | |
| 355 | + \ThinkRank\SEO\Content_Type_Settings::FEATURE_SCHEMA, | |
| 356 | + $post_type, | |
| 357 | + true | |
| 358 | + )) { | |
| 359 | + return false; | |
| 360 | + } | |
| 361 | + | |
| 331 | 362 | $settings = $this->get_global_seo_settings($post_type); |
| 332 | 363 | |
| 333 | 364 | return !empty($settings['schema_type']); |
| 334 | 365 | } |