PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.7.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.7.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
← All changes | includes/api/class-performance-endpoint.php +54 -14 2.0.02.7.0 View file →
@@ -353,16 +353,17 @@
353 353 try {
354 354 // Get device type from request
355 355 $device_type = $request->get_param('device_type') ?? 'mobile';
356 356
357 - $opportunities = $this->get_performance_manager()->get_performance_opportunities('', $device_type);
357 + $manager = $this->get_performance_manager();
358 + $opportunities = $manager->get_performance_opportunities('', $device_type);
358 359
359 - return new WP_REST_Response([
360 - 'success' => true,
361 - 'data' => $opportunities,
362 - 'device_type' => $device_type,
363 - 'message' => __('Performance opportunities retrieved successfully', 'thinkrank')
364 - ], 200);
360 + return $this->pagespeed_list_response(
361 + $manager,
362 + $opportunities,
363 + $device_type,
364 + __('Performance opportunities retrieved successfully', 'thinkrank')
365 + );
365 366
366 367 } catch (\Exception $e) {
367 368 return new WP_Error(
368 369 'opportunities_failed',
@@ -384,16 +385,17 @@
384 385 try {
385 386 // Get device type from request
386 387 $device_type = $request->get_param('device_type') ?? 'mobile';
387 388
388 - $diagnostics = $this->get_performance_manager()->get_performance_diagnostics('', $device_type);
389 + $manager = $this->get_performance_manager();
390 + $diagnostics = $manager->get_performance_diagnostics('', $device_type);
389 391
390 - return new WP_REST_Response([
391 - 'success' => true,
392 - 'data' => $diagnostics,
393 - 'device_type' => $device_type,
394 - 'message' => __('Performance diagnostics retrieved successfully', 'thinkrank')
395 - ], 200);
392 + return $this->pagespeed_list_response(
393 + $manager,
394 + $diagnostics,
395 + $device_type,
396 + __('Performance diagnostics retrieved successfully', 'thinkrank')
397 + );
396 398
397 399 } catch (\Exception $e) {
398 400 return new WP_Error(
399 401 'diagnostics_failed',
@@ -532,8 +534,46 @@
532 534 * @since 1.0.0
533 535 *
534 536 * @return array Arguments array
535 537 */
538 + /**
539 + * Wrap a PageSpeed-backed list, reporting whether it was actually fetched.
540 + *
541 + * An empty list used to come back as `success: true` /
542 + * "retrieved successfully" whether the site was clean, the request had
543 + * failed, or nothing had been attempted for want of a credential — so no
544 + * API or MCP consumer could tell the three apart, and the admin UI told
545 + * everyone to connect Google (#519). The list itself keeps its shape.
546 + *
547 + * @since 2.1.1
548 + *
549 + * @param Performance_Monitoring_Manager $manager Manager that produced the list.
550 + * @param array $data The list.
551 + * @param string $device_type Device the list is for.
552 + * @param string $success_message Message for a completed request.
553 + * @return WP_REST_Response
554 + */
555 + private function pagespeed_list_response(Performance_Monitoring_Manager $manager, array $data, string $device_type, string $success_message): WP_REST_Response {
556 + $error = $manager->get_last_error();
557 +
558 + if ('' !== $error['code']) {
559 + return new WP_REST_Response([
560 + 'success' => false,
561 + 'data' => $data,
562 + 'device_type' => $device_type,
563 + 'error_code' => $error['code'],
564 + 'message' => $error['message'],
565 + ], 200);
566 + }
567 +
568 + return new WP_REST_Response([
569 + 'success' => true,
570 + 'data' => $data,
571 + 'device_type' => $device_type,
572 + 'message' => $success_message,
573 + ], 200);
574 + }
575 +
536 576 private function get_historical_data_args(): array {
537 577 return [
538 578 'days' => [
539 579 'required' => false,