| @@ -300,14 +300,25 @@ | ||
| 300 | 300 | // applied over the correct server-side analysis this request had just |
| 301 | 301 | // run, then persisted by save_score(). That is what put "No content" |
| 302 | 302 | // on the dashboard for a page with a valid score (#778). With nothing |
| 303 | 303 | // measured, the analysis above is the better answer. |
| 304 | + // | |
| 305 | + // Non-empty `live_content` is not on its own proof that the editor | |
| 306 | + // measured anything: builder markup (Divi 5) is markup the editor | |
| 307 | + // has plenty of and can read no words from, so it sent that same | |
| 308 | + // "No content" pair alongside 450 characters of block comments. | |
| 309 | + // Treat the sentinel itself as "nothing measured" whenever this | |
| 310 | + // request's own analysis did find words, so a stale bundle cannot | |
| 311 | + // overwrite a valid analysis either. | |
| 304 | 312 | $editor_measured = '' !== trim((string) $live_content); |
| 313 | + $server_found_content = ($content_data['word_count'] ?? 0) > 0; | |
| 305 | 314 | |
| 306 | - if ($editor_measured && null !== $readability_score) { | |
| 315 | + if ($editor_measured && null !== $readability_score | |
| 316 | + && !($server_found_content && self::is_no_content_label($readability_score))) { | |
| 307 | 317 | $score_data['readability_score'] = $readability_score; |
| 308 | 318 | } |
| 309 | - if ($editor_measured && null !== $content_quality) { | |
| 319 | + if ($editor_measured && null !== $content_quality | |
| 320 | + && !($server_found_content && self::is_no_content_label($content_quality))) { | |
| 310 | 321 | $score_data['content_quality'] = $content_quality; |
| 311 | 322 | } |
| 312 | 323 | |
| 313 | 324 | // Save score if requested |
| @@ -331,8 +342,25 @@ | ||
| 331 | 342 | 'Failed to calculate SEO score: ' . $e->getMessage(), |
| 332 | 343 | ['status' => 500] |
| 333 | 344 | ); |
| 334 | 345 | } |
| 346 | + } | |
| 347 | + | |
| 348 | + /** | |
| 349 | + * Whether an editor-supplied label means "I could not read the content". | |
| 350 | + * | |
| 351 | + * `calculateReadabilityScore()` and `calculateContentQuality()` both return | |
| 352 | + * this exact untranslated string when handed an empty body, so it is the | |
| 353 | + * editor saying it measured nothing rather than a measurement in its own | |
| 354 | + * right. Every real label carries a level or a grade. | |
| 355 | + * | |
| 356 | + * @since 2.12.0 | |
| 357 | + * | |
| 358 | + * @param mixed $label Label sent by the editor. | |
| 359 | + * @return bool True when the label is the empty-content sentinel. | |
| 360 | + */ | |
| 361 | + private static function is_no_content_label($label): bool { | |
| 362 | + return is_string($label) && 'no content' === strtolower(trim($label)); | |
| 335 | 363 | } |
| 336 | 364 | |
| 337 | 365 | /** |
| 338 | 366 | * Get existing SEO score for a post |