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
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.7.0, at includes/abilities/settings/class-get-email-report-settings.php

129 lines 3.4 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), the next scheduled
24 * run and the section catalog. Read-only.
25 */
26 class Get_Email_Report_Settings extends Ability_Base {
27 /**
28 * Constructor.
29 */
30 public function __construct() {
31 $this->id = 'thinkrank/get-email-report-settings';
32 $this->label = __( 'Get ThinkRank Email Report Settings', 'thinkrank' );
33 $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, and the section catalog. Use update-email-report-settings to switch it on or off, and send-email-report-test to send one now.', 'thinkrank' );
34 }
35
36 /**
37 * {@inheritDoc}
38 *
39 * @return array<string, bool|float|string>
40 */
41 public function get_annotations() {
42 return [
43 'readonly' => true,
44 'destructive' => false,
45 'idempotent' => true,
46 'priority' => 1.0,
47 'openWorldHint' => false,
48 ];
49 }
50
51 /**
52 * {@inheritDoc}
53 *
54 * @return array<string, mixed>
55 */
56 public function get_input_schema() {
57 return [
58 'type' => 'object',
59 'additionalProperties' => false,
60 'properties' => self::empty_properties(),
61 ];
62 }
63
64 /**
65 * {@inheritDoc}
66 *
67 * @return array<string, mixed>
68 */
69 public function get_output_schema() {
70 return [
71 'type' => 'object',
72 'properties' => [
73 'config' => [
74 'type' => 'object',
75 'description' => __( 'The resolved Email Reporting config: enabled, frequency_days, recipients, sections_enabled and the schedule timestamps.', 'thinkrank' ),
76 'additionalProperties' => true,
77 ],
78 'next_run' => [
79 'type' => [ 'string', 'null' ],
80 'description' => __( 'ISO-8601 timestamp of the next scheduled report, or null when disabled.', 'thinkrank' ),
81 ],
82 'sections' => [
83 'type' => 'array',
84 'description' => __( 'The available report sections and their labels.', 'thinkrank' ),
85 ],
86 ],
87 ];
88 }
89
90 /**
91 * Execute ability.
92 *
93 * @param array<string, mixed> $input Ability input payload.
94 * @return array<string, mixed>|\WP_Error
95 */
96 public function execute( $input ) {
97 $manager = $this->resolve_manager();
98
99 if ( ! $manager instanceof Email_Report_Manager ) {
100 return new \WP_Error(
101 'thinkrank_email_report_unavailable',
102 __( 'Email Report Manager is unavailable.', 'thinkrank' ),
103 [ 'status' => 500 ]
104 );
105 }
106
107 return [
108 'config' => $manager->config()->get(),
109 'next_run' => $manager->scheduler()->next_run_iso(),
110 'sections' => $manager->registry()->describe_for_ui(),
111 ];
112 }
113
114 /**
115 * Resolve the shared Email_Report_Manager from the plugin container.
116 *
117 * @return Email_Report_Manager|null
118 */
119 private function resolve_manager() {
120 if ( ! function_exists( 'thinkrank' ) ) {
121 return null;
122 }
123
124 $component = thinkrank()->get_component( 'email_report' );
125
126 return $component instanceof Email_Report_Manager ? $component : null;
127 }
128 }
129