PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.0.2
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.0.2
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
thinkrank / includes / abilities / analysis / class-get-seo-insights.php

class-get-seo-insights.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 2.0.2, at includes/abilities/analysis/class-get-seo-insights.php

103 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get SEO insights ability.
4 *
5 * @package ThinkRank\Abilities\Analysis
6 */
7
8 declare(strict_types=1);
9
10 namespace ThinkRank\Abilities\Analysis;
11
12 use ThinkRank\Abilities\Ability_Base;
13 use ThinkRank\SEO\Analytics_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank AI-generated SEO insights.
21 *
22 * Requires a Google connection and, for AI insights, ThinkRank Pro. When those
23 * are unavailable the manager returns a message such as
24 * { success: false, message: 'requires ThinkRank Pro' }, which is passed
25 * through unchanged.
26 */
27 class Get_Seo_Insights extends Ability_Base {
28 /**
29 * Constructor.
30 */
31 public function __construct() {
32 $this->id = 'thinkrank/get-seo-insights';
33 $this->label = __( 'Get ThinkRank SEO Insights', 'thinkrank' );
34 $this->description = __( 'Retrieve ThinkRank AI-generated SEO insights. Requires a Google connection and, for AI insights, ThinkRank Pro; otherwise a "requires ThinkRank Pro" message is returned.', 'thinkrank' );
35 }
36
37 /**
38 * {@inheritDoc}
39 *
40 * @return array<string, bool|float|string>
41 */
42 public function get_annotations() {
43 return [
44 'readonly' => true,
45 'destructive' => false,
46 'idempotent' => true,
47 'priority' => 1.0,
48 'openWorldHint' => false,
49 ];
50 }
51
52 /**
53 * {@inheritDoc}
54 *
55 * @return array<string, mixed>
56 */
57 public function get_input_schema() {
58 return [
59 'type' => 'object',
60 'additionalProperties' => false,
61 'properties' => [
62 'date_range' => [
63 'type' => 'string',
64 'description' => __( 'The reporting date range.', 'thinkrank' ),
65 'enum' => [ '7d', '30d', '90d' ],
66 'default' => '30d',
67 ],
68 ],
69 ];
70 }
71
72 /**
73 * {@inheritDoc}
74 *
75 * @return array<string, mixed>
76 */
77 public function get_output_schema() {
78 return [
79 'type' => 'object',
80 'additionalProperties' => true,
81 'properties' => self::empty_properties(),
82 ];
83 }
84
85 /**
86 * Execute ability.
87 *
88 * @param array<string, mixed> $input Ability input payload.
89 * @return array<string, mixed>
90 */
91 public function execute( $input ) {
92 $date_range = isset( $input['date_range'] ) ? (string) $input['date_range'] : '30d';
93
94 if ( ! in_array( $date_range, [ '7d', '30d', '90d' ], true ) ) {
95 $date_range = '30d';
96 }
97
98 $manager = new Analytics_Manager();
99
100 return $manager->get_seo_insights( $date_range );
101 }
102 }
103