PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.3.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.3.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.3.0, at includes/abilities/settings/class-get-email-report-settings.php

148 lines 4.2 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\Core\Plan_Config;
14 use ThinkRank\SEO\Email_Report_Manager;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Retrieves ThinkRank Email Reporting settings.
22 *
23 * Mirrors `GET /thinkrank/v1/email-report/config`: returns the per-site report
24 * config (enable toggle, frequency, recipients, branding/content fields), the
25 * plan capability map (which fields are editable on the current plan), the next
26 * scheduled run, the available report sections, and the tokens usable in text
27 * fields. Read-only.
28 */
29 class Get_Email_Report_Settings extends Ability_Base {
30 /**
31 * Constructor.
32 */
33 public function __construct() {
34 $this->id = 'thinkrank/get-email-report-settings';
35 $this->label = __( 'Get ThinkRank Email Report Settings', 'thinkrank' );
36 $this->description = __( 'Retrieve ThinkRank Email Reporting settings: enable toggle, frequency, recipients, branding/content fields, the plan capability map, the next scheduled send, the available report sections, and the tokens usable in text fields. Use update-email-report-settings to change them, and send-email-report-test to send one now.', 'thinkrank' );
37 }
38
39 /**
40 * {@inheritDoc}
41 *
42 * @return array<string, bool|float|string>
43 */
44 public function get_annotations() {
45 return [
46 'readonly' => true,
47 'destructive' => false,
48 'idempotent' => true,
49 'priority' => 1.0,
50 'openWorldHint' => false,
51 ];
52 }
53
54 /**
55 * {@inheritDoc}
56 *
57 * @return array<string, mixed>
58 */
59 public function get_input_schema() {
60 return [
61 'type' => 'object',
62 'additionalProperties' => false,
63 'properties' => self::empty_properties(),
64 ];
65 }
66
67 /**
68 * {@inheritDoc}
69 *
70 * @return array<string, mixed>
71 */
72 public function get_output_schema() {
73 return [
74 'type' => 'object',
75 'properties' => [
76 'config' => [
77 'type' => 'object',
78 'description' => __( 'The current per-site Email Reporting config.', 'thinkrank' ),
79 'additionalProperties' => true,
80 ],
81 'capabilities' => [
82 'type' => 'object',
83 'description' => __( 'Which fields the current plan allows editing.', 'thinkrank' ),
84 'additionalProperties' => true,
85 ],
86 'next_run' => [
87 'type' => [ 'string', 'null' ],
88 'description' => __( 'ISO-8601 timestamp of the next scheduled report, or null when disabled.', 'thinkrank' ),
89 ],
90 'sections' => [
91 'type' => 'array',
92 'description' => __( 'The available report sections and their labels.', 'thinkrank' ),
93 ],
94 'tokens' => [
95 'type' => 'object',
96 'description' => __( 'Tokens usable in subject/intro/footer text.', 'thinkrank' ),
97 'additionalProperties' => true,
98 ],
99 ],
100 ];
101 }
102
103 /**
104 * Execute ability.
105 *
106 * @param array<string, mixed> $input Ability input payload.
107 * @return array<string, mixed>|\WP_Error
108 */
109 public function execute( $input ) {
110 $manager = $this->resolve_manager();
111
112 if ( ! $manager instanceof Email_Report_Manager ) {
113 return new \WP_Error(
114 'thinkrank_email_report_unavailable',
115 __( 'Email Report Manager is unavailable.', 'thinkrank' ),
116 [ 'status' => 500 ]
117 );
118 }
119
120 if ( ! function_exists( 'thinkrank_get_email_report_tokens' ) ) {
121 require_once THINKRANK_PLUGIN_DIR . 'includes/config/email-report-settings-config.php';
122 }
123
124 return [
125 'config' => $manager->config()->get(),
126 'capabilities' => Plan_Config::email_report(),
127 'next_run' => $manager->scheduler()->next_run_iso(),
128 'sections' => $manager->registry()->describe_for_ui(),
129 'tokens' => thinkrank_get_email_report_tokens(),
130 ];
131 }
132
133 /**
134 * Resolve the shared Email_Report_Manager from the plugin container.
135 *
136 * @return Email_Report_Manager|null
137 */
138 private function resolve_manager() {
139 if ( ! function_exists( 'thinkrank' ) ) {
140 return null;
141 }
142
143 $component = thinkrank()->get_component( 'email_report' );
144
145 return $component instanceof Email_Report_Manager ? $component : null;
146 }
147 }
148