PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.8.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.8.0
2.8.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 All 49 releases
thinkrank / includes / abilities / settings / class-get-email-report-settings.php

class-get-email-report-settings.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 2.8.0, at includes/abilities/settings/class-get-email-report-settings.php

142 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get email report settings ability.
4 *
5 * @package ThinkRank\Abilities\Settings
6 */
7
8 declare(strict_types=1);
9
10 namespace ThinkRank\Abilities\Settings;
11
12 use ThinkRank\Abilities\Ability_Base;
13 use ThinkRank\SEO\Email_Report_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank Email Reporting settings.
21 *
22 * Mirrors `GET /thinkrank/v1/email-report/config`: returns the resolved report
23 * config (on/off, frequency, recipients, enabled sections, why the last
24 * scheduled run sent nothing), the next scheduled run, the section catalog
25 * and the readiness of the data sources. Read-only.
26 */
27 class Get_Email_Report_Settings extends Ability_Base {
28 /**
29 * Constructor.
30 */
31 public function __construct() {
32 $this->id = 'thinkrank/get-email-report-settings';
33 $this->label = __( 'Get ThinkRank Email Report Settings', 'thinkrank' );
34 $this->description = __( 'Retrieve ThinkRank Email Reporting settings: whether the scheduled SEO report is on, how often it is sent (days), who receives it, which sections it includes, the next scheduled send, the section catalog, and readiness — whether Google Search Console is connected (required; scheduled reports are paused and config.last_skip says why while it is not), and whether Google Analytics 4 and AI-assistant traffic data are available to add their sections. Use update-email-report-settings to switch it on or off, and send-email-report-test to send one now.', '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' => self::empty_properties(),
62 ];
63 }
64
65 /**
66 * {@inheritDoc}
67 *
68 * @return array<string, mixed>
69 */
70 public function get_output_schema() {
71 return [
72 'type' => 'object',
73 'properties' => [
74 'config' => [
75 'type' => 'object',
76 'description' => __( 'The resolved Email Reporting config: enabled, frequency_days, recipients, sections_enabled, the schedule timestamps, and last_skip ({reason, at} or null) — why the last scheduled run sent nothing: search_console_not_connected or no_data.', 'thinkrank' ),
77 'additionalProperties' => true,
78 ],
79 'readiness' => [
80 'type' => 'object',
81 'description' => __( 'Data-source readiness: ready (bool — a report can be built), search_console (bool, required), analytics (bool — Google Analytics 4 connected, adds the site-traffic section), ai_traffic (bool — AI-assistant referrals recorded, adds that section), reason (string|null — search_console_not_connected when not ready).', 'thinkrank' ),
82 'properties' => [
83 'ready' => [ 'type' => 'boolean' ],
84 'search_console' => [ 'type' => 'boolean' ],
85 'analytics' => [ 'type' => 'boolean' ],
86 'ai_traffic' => [ 'type' => 'boolean' ],
87 'reason' => [ 'type' => [ 'string', 'null' ] ],
88 ],
89 ],
90 'next_run' => [
91 'type' => [ 'string', 'null' ],
92 'description' => __( 'ISO-8601 timestamp of the next scheduled report, or null when disabled.', 'thinkrank' ),
93 ],
94 'sections' => [
95 'type' => 'array',
96 'description' => __( 'The available report sections and their labels.', 'thinkrank' ),
97 ],
98 ],
99 ];
100 }
101
102 /**
103 * Execute ability.
104 *
105 * @param array<string, mixed> $input Ability input payload.
106 * @return array<string, mixed>|\WP_Error
107 */
108 public function execute( $input ) {
109 $manager = $this->resolve_manager();
110
111 if ( ! $manager instanceof Email_Report_Manager ) {
112 return new \WP_Error(
113 'thinkrank_email_report_unavailable',
114 __( 'Email Report Manager is unavailable.', 'thinkrank' ),
115 [ 'status' => 500 ]
116 );
117 }
118
119 return [
120 'config' => $manager->config()->get(),
121 'next_run' => $manager->scheduler()->next_run_iso(),
122 'sections' => $manager->registry()->describe_for_ui(),
123 'readiness' => $manager->data_provider()->readiness(),
124 ];
125 }
126
127 /**
128 * Resolve the shared Email_Report_Manager from the plugin container.
129 *
130 * @return Email_Report_Manager|null
131 */
132 private function resolve_manager() {
133 if ( ! function_exists( 'thinkrank' ) ) {
134 return null;
135 }
136
137 $component = thinkrank()->get_component( 'email_report' );
138
139 return $component instanceof Email_Report_Manager ? $component : null;
140 }
141 }
142