| @@ -347,8 +347,10 @@ | ||
| 347 | 347 | // Get existing score data from database |
| 348 | 348 | $existing_data = $this->calculator->get_existing_score_data($post_id); |
| 349 | 349 | |
| 350 | 350 | if ($existing_data) { |
| 351 | + $existing_data['keywords'] = $this->keyword_placements((int) $post_id); | |
| 352 | + | |
| 351 | 353 | return new WP_REST_Response([ |
| 352 | 354 | 'success' => true, |
| 353 | 355 | 'data' => $existing_data, |
| 354 | 356 | 'message' => __('Existing SEO score retrieved successfully', 'thinkrank') |
| @@ -366,8 +368,27 @@ | ||
| 366 | 368 | } |
| 367 | 369 | } |
| 368 | 370 | |
| 369 | 371 | /** |
| 372 | + * Where each focus keyword sits (#729), for a stored score. A stored score | |
| 373 | + * predates the editor's current keywords and content, so this is read | |
| 374 | + * from the post as saved now — a text pass, no request, no AI. | |
| 375 | + * | |
| 376 | + * @param int $post_id Post ID. | |
| 377 | + * @return array<int, array<string, mixed>> | |
| 378 | + */ | |
| 379 | + private function keyword_placements(int $post_id): array { | |
| 380 | + return $this->calculator->keyword_placements( | |
| 381 | + $this->calculator->analyze_post_content($post_id), | |
| 382 | + [ | |
| 383 | + 'title' => \ThinkRank\SEO\Pattern_Resolver::effective_title($post_id), | |
| 384 | + 'description' => \ThinkRank\SEO\Pattern_Resolver::effective_description($post_id), | |
| 385 | + ], | |
| 386 | + \ThinkRank\SEO\Focus_Keywords::get($post_id) | |
| 387 | + ); | |
| 388 | + } | |
| 389 | + | |
| 390 | + /** | |
| 370 | 391 | * Get score history for a post |
| 371 | 392 | * |
| 372 | 393 | * @param WP_REST_Request $request Request object |
| 373 | 394 | * @return WP_REST_Response|WP_Error Response object |
| @@ -402,10 +423,14 @@ | ||
| 402 | 423 | public function get_latest_score(WP_REST_Request $request) { |
| 403 | 424 | try { |
| 404 | 425 | $post_id = $request->get_param('post_id'); |
| 405 | 426 | |
| 427 | + // The stored row only — no keyword gauges (#729). The dashboard | |
| 428 | + // asks for five posts at once and reads overall_score; a gauge | |
| 429 | + // pass would analyse and render each whole post for nothing. The | |
| 430 | + // editor reads its gauges from /seo-score/get. | |
| 406 | 431 | $latest_score = $this->calculator->get_latest_score($post_id); |
| 407 | - | |
| 432 | + | |
| 408 | 433 | return new WP_REST_Response([ |
| 409 | 434 | 'success' => true, |
| 410 | 435 | 'data' => $latest_score, |
| 411 | 436 | ], 200); |