PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.9.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.9.0
2.9.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 All 50 releases
thinkrank / includes / seo / class-email-report-manager.php

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

152 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Email Report Manager (Boot)
4 *
5 * The single component the plugin's DI container instantiates. Wires
6 * together the config, registry, renderer, mailer, generator, and
7 * scheduler, then registers the cron and the section catalog.
8 *
9 * Free sections are require_once'd here because the project autoloader
10 * doesn't translate underscores in sub-namespaces to hyphenated
11 * directories. Pro can register more sections via the
12 * `thinkrank_email_report_register_sections` action.
13 *
14 * @package ThinkRank
15 * @subpackage SEO
16 * @since 1.9.0
17 */
18
19 declare(strict_types=1);
20
21 namespace ThinkRank\SEO;
22
23 use ThinkRank\SEO\Email_Report_Sections\Email_Report_Section_Interface;
24 use ThinkRank\SEO\Email_Report_Sections\Key_Metrics_Section;
25 use ThinkRank\SEO\Email_Report_Sections\Position_Summary_Section;
26 use ThinkRank\SEO\Email_Report_Sections\Top_Winning_Posts_Section;
27 use ThinkRank\SEO\Email_Report_Sections\Top_Losing_Posts_Section;
28 use ThinkRank\SEO\Email_Report_Sections\Top_Winning_Keywords_Section;
29 use ThinkRank\SEO\Email_Report_Sections\Top_Losing_Keywords_Section;
30 use ThinkRank\SEO\Email_Report_Sections\Site_Traffic_Section;
31 use ThinkRank\SEO\Email_Report_Sections\Ai_Search_Section;
32
33 if (!defined('ABSPATH')) {
34 exit;
35 }
36
37 /**
38 * Email_Report_Manager
39 *
40 * @since 1.9.0
41 */
42 final class Email_Report_Manager {
43
44 private ?Email_Report_Config $config = null;
45 private ?Email_Report_Section_Registry $registry = null;
46 private ?Email_Report_Renderer $renderer = null;
47 private ?Email_Report_Mailer $mailer = null;
48 private ?Email_Report_Generator $generator = null;
49 private ?Email_Report_Scheduler $scheduler = null;
50 private ?Email_Report_Data_Provider $data_provider = null;
51
52 /**
53 * Called by the plugin DI container at plugins_loaded.
54 *
55 * Two-phase: load files now (so endpoint classes can resolve types
56 * during rest_api_init), then register cron/sections on init.
57 */
58 public function init(): void {
59 $this->require_files();
60 $this->build_graph();
61 $this->register_default_sections();
62 $this->register_extension_sections();
63 $this->scheduler->register();
64 }
65
66 /**
67 * Section files live under `seo/email-report-sections/` (hyphenated)
68 * but the namespace uses underscores — autoloader can't bridge that
69 * mismatch. Explicit require keeps boot order deterministic.
70 */
71 private function require_files(): void {
72 $base = THINKRANK_PLUGIN_DIR . 'includes/seo/email-report-sections/';
73 require_once $base . 'interface-email-report-section.php';
74 require_once $base . 'class-email-report-html.php';
75 require_once $base . 'class-top-posts-renderer.php';
76 require_once $base . 'class-key-metrics-section.php';
77 require_once $base . 'class-position-summary-section.php';
78 require_once $base . 'class-top-winning-posts-section.php';
79 require_once $base . 'class-top-losing-posts-section.php';
80 require_once $base . 'class-top-winning-keywords-section.php';
81 require_once $base . 'class-top-losing-keywords-section.php';
82 require_once $base . 'class-site-traffic-section.php';
83 require_once $base . 'class-ai-search-section.php';
84
85 // Defaults config is procedural — load eagerly.
86 require_once THINKRANK_PLUGIN_DIR . 'includes/config/email-report-settings-config.php';
87 }
88
89 private function build_graph(): void {
90 $this->config = new Email_Report_Config();
91 $this->registry = new Email_Report_Section_Registry();
92 $this->renderer = new Email_Report_Renderer($this->registry);
93 $this->mailer = new Email_Report_Mailer();
94 $this->data_provider = new Email_Report_Data_Provider();
95 $this->generator = new Email_Report_Generator(
96 $this->config,
97 $this->renderer,
98 $this->mailer,
99 $this->data_provider
100 );
101 $this->scheduler = new Email_Report_Scheduler($this->config, $this->generator);
102 }
103
104 private function register_default_sections(): void {
105 // Registration order is render order: the hero, what grew, what
106 // fell, where things rank, then the optional GA4 and AI cards.
107 $this->registry->register(new Key_Metrics_Section());
108 $this->registry->register(new Top_Winning_Posts_Section());
109 $this->registry->register(new Top_Winning_Keywords_Section());
110 $this->registry->register(new Top_Losing_Posts_Section());
111 $this->registry->register(new Top_Losing_Keywords_Section());
112 $this->registry->register(new Position_Summary_Section());
113 $this->registry->register(new Site_Traffic_Section());
114 $this->registry->register(new Ai_Search_Section());
115 }
116
117 private function register_extension_sections(): void {
118 /**
119 * Pro plugin (or any other plugin) hooks here and calls
120 * $registry->register(new MySection())
121 * to add or override a section.
122 *
123 * @since 1.9.0
124 *
125 * @param Email_Report_Section_Registry $registry
126 */
127 do_action('thinkrank_email_report_register_sections', $this->registry);
128 }
129
130 // Accessors used by the REST endpoint.
131
132 public function config(): Email_Report_Config {
133 return $this->config;
134 }
135
136 public function registry(): Email_Report_Section_Registry {
137 return $this->registry;
138 }
139
140 public function generator(): Email_Report_Generator {
141 return $this->generator;
142 }
143
144 public function scheduler(): Email_Report_Scheduler {
145 return $this->scheduler;
146 }
147
148 public function data_provider(): Email_Report_Data_Provider {
149 return $this->data_provider;
150 }
151 }
152