PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.10.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.10.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 / ai / class-prompt-builder.php

class-prompt-builder.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.10.0, at includes/ai/class-prompt-builder.php

300 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AI Prompt Builder Class
4 *
5 * Coordinator class that delegates to specialized prompt classes.
6 * Provides consistent interface while organizing prompts by type.
7 * Supports LLMs.txt, SEO, Site Identity, Homepage, and other AI-powered features.
8 *
9 * @package ThinkRank
10 * @subpackage AI
11 * @since 1.0.0
12 */
13
14 declare(strict_types=1);
15
16 namespace ThinkRank\AI;
17
18 // Prevent direct access
19 if (!defined('ABSPATH')) {
20 exit;
21 }
22
23 use ThinkRank\AI\Prompts\SEO_Prompts;
24 use ThinkRank\AI\Prompts\Site_Identity_Prompts;
25 use ThinkRank\AI\Prompts\Homepage_Prompts;
26 use ThinkRank\AI\Prompts\LLMs_Txt_Prompts;
27 use ThinkRank\AI\Prompts\Content_Brief_Prompts;
28
29 /**
30 * AI Prompt Builder Class
31 *
32 * Coordinator class that delegates to specialized prompt classes.
33 * Provides consistent interface for all AI optimization prompts.
34 *
35 * @since 1.0.0
36 */
37 class Prompt_Builder {
38
39 /**
40 * SEO Prompts instance
41 *
42 * @since 1.0.0
43 * @var SEO_Prompts|null
44 */
45 private ?SEO_Prompts $seo_prompts = null;
46
47 /**
48 * Site Identity Prompts instance
49 *
50 * @since 1.0.0
51 * @var Site_Identity_Prompts|null
52 */
53 private ?Site_Identity_Prompts $site_identity_prompts = null;
54
55 /**
56 * Homepage Prompts instance
57 *
58 * @since 1.0.0
59 * @var Homepage_Prompts|null
60 */
61 private ?Homepage_Prompts $homepage_prompts = null;
62
63 /**
64 * LLMs.txt Prompts instance
65 *
66 * @since 1.0.0
67 * @var LLMs_Txt_Prompts|null
68 */
69 private ?LLMs_Txt_Prompts $llms_txt_prompts = null;
70
71 /**
72 * Content Brief Prompts instance
73 *
74 * @since 1.0.0
75 * @var Content_Brief_Prompts|null
76 */
77 private ?Content_Brief_Prompts $content_brief_prompts = null;
78
79 /**
80 * Build LLMs.txt optimization prompt
81 *
82 * @since 1.0.0
83 *
84 * @param array $website_data Website data to optimize
85 * @param array $options Optimization options
86 * @param string $provider AI provider ('openai', 'claude', etc.)
87 * @return string Formatted prompt
88 */
89 public function build_llms_txt_prompt(array $website_data, array $options = [], string $provider = 'openai'): string {
90 return $this->get_llms_txt_prompts()->build_llms_txt_prompt($website_data, $options, $provider);
91 }
92
93 /**
94 * Build SEO metadata optimization prompt
95 *
96 * @since 1.0.0
97 *
98 * @param string $content Content to optimize
99 * @param string $target_keyword Target keyword
100 * @param string $content_type Type of content
101 * @param string $tone Desired tone
102 * @param string $provider AI provider
103 * @return string Formatted prompt
104 */
105 public function build_seo_prompt(string $content, string $target_keyword, string $content_type, string $tone, string $provider = 'openai'): string {
106 return $this->get_seo_prompts()->build_seo_prompt($content, $target_keyword, $content_type, $tone, $provider);
107 }
108
109 /**
110 * Build content analysis prompt
111 *
112 * @since 1.0.0
113 *
114 * @param string $content Content to analyze
115 * @param array $metadata Existing metadata
116 * @param string $provider AI provider
117 * @return string Formatted prompt
118 */
119 public function build_analysis_prompt(string $content, array $metadata, string $provider = 'openai'): string {
120 return $this->get_seo_prompts()->build_analysis_prompt($content, $metadata, $provider);
121 }
122
123 /**
124 * Build site identity optimization prompt
125 *
126 * @since 1.0.0
127 *
128 * @param array $site_data Site data to optimize
129 * @param string $business_type Business type
130 * @param string $target_audience Target audience
131 * @param string $tone Desired tone
132 * @param string $provider AI provider
133 * @return string Formatted prompt
134 */
135 public function build_site_identity_prompt(array $site_data, string $business_type, string $target_audience, string $tone, string $provider = 'openai'): string {
136 return $this->get_site_identity_prompts()->build_site_identity_prompt($site_data, $business_type, $target_audience, $tone, $provider);
137 }
138
139 /**
140 * Build homepage meta optimization prompt
141 *
142 * @since 1.0.0
143 *
144 * @param array $content_data Meta content data
145 * @param string $business_type Business type
146 * @param string $target_audience Target audience
147 * @param string $tone Content tone
148 * @param array $context Additional context information
149 * @param string $provider AI provider
150 * @return string Formatted prompt
151 */
152 public function build_homepage_meta_prompt(array $content_data, string $business_type, string $target_audience, string $tone, array $context = [], string $provider = 'openai'): string {
153 return $this->get_homepage_prompts()->build_homepage_meta_prompt($content_data, $business_type, $target_audience, $tone, $context, $provider);
154 }
155
156 /**
157 * Build homepage hero optimization prompt
158 *
159 * @since 1.0.0
160 *
161 * @param array $hero_data Hero content data
162 * @param string $business_type Business type
163 * @param string $target_audience Target audience
164 * @param string $tone Content tone
165 * @param array $context Additional context information
166 * @param string $provider AI provider
167 * @return string Formatted prompt
168 */
169 public function build_homepage_hero_prompt(array $hero_data, string $business_type, string $target_audience, string $tone, array $context = [], string $provider = 'openai'): string {
170 return $this->get_homepage_prompts()->build_homepage_hero_prompt($hero_data, $business_type, $target_audience, $tone, $context, $provider);
171 }
172
173 /**
174 * Build content brief generation prompt
175 *
176 * @since 1.0.0
177 *
178 * @param array $target_keywords Primary and secondary keywords
179 * @param string $content_type Type of content
180 * @param string $target_audience Target audience
181 * @param string $content_length Desired content length
182 * @param string $tone Content tone
183 * @param string $competitor_analysis Pre-analyzed competitor content (or empty string)
184 * @param string $additional_context Additional context
185 * @param string $provider AI provider
186 * @return string Generated prompt
187 */
188 public function build_content_brief_prompt(
189 array $target_keywords,
190 string $content_type,
191 string $target_audience,
192 string $content_length,
193 string $tone,
194 string $competitor_analysis,
195 string $additional_context,
196 string $provider = 'openai'
197 ): string {
198 return $this->get_content_brief_prompts()->build_content_brief_prompt(
199 $target_keywords,
200 $content_type,
201 $target_audience,
202 $content_length,
203 $tone,
204 $competitor_analysis,
205 $additional_context,
206 $provider
207 );
208 }
209
210 /**
211 * Get SEO Prompts instance
212 *
213 * @since 1.0.0
214 *
215 * @return SEO_Prompts SEO Prompts instance
216 */
217 private function get_seo_prompts(): SEO_Prompts {
218 if (!$this->seo_prompts) {
219 // Ensure SEO Prompts is loaded
220 if (!class_exists('ThinkRank\\AI\\Prompts\\SEO_Prompts')) {
221 require_once THINKRANK_PLUGIN_DIR . 'includes/ai/prompts/class-seo-prompts.php';
222 }
223 $this->seo_prompts = new SEO_Prompts();
224 }
225 return $this->seo_prompts;
226 }
227
228 /**
229 * Get Site Identity Prompts instance
230 *
231 * @since 1.0.0
232 *
233 * @return Site_Identity_Prompts Site Identity Prompts instance
234 */
235 private function get_site_identity_prompts(): Site_Identity_Prompts {
236 if (!$this->site_identity_prompts) {
237 // Ensure Site Identity Prompts is loaded
238 if (!class_exists('ThinkRank\\AI\\Prompts\\Site_Identity_Prompts')) {
239 require_once THINKRANK_PLUGIN_DIR . 'includes/ai/prompts/class-site-identity-prompts.php';
240 }
241 $this->site_identity_prompts = new Site_Identity_Prompts();
242 }
243 return $this->site_identity_prompts;
244 }
245
246 /**
247 * Get Homepage Prompts instance
248 *
249 * @since 1.0.0
250 *
251 * @return Homepage_Prompts Homepage Prompts instance
252 */
253 private function get_homepage_prompts(): Homepage_Prompts {
254 if (!$this->homepage_prompts) {
255 // Ensure Homepage Prompts is loaded
256 if (!class_exists('ThinkRank\\AI\\Prompts\\Homepage_Prompts')) {
257 require_once THINKRANK_PLUGIN_DIR . 'includes/ai/prompts/class-homepage-prompts.php';
258 }
259 $this->homepage_prompts = new Homepage_Prompts();
260 }
261 return $this->homepage_prompts;
262 }
263
264 /**
265 * Get LLMs.txt Prompts instance
266 *
267 * @since 1.0.0
268 *
269 * @return LLMs_Txt_Prompts LLMs.txt Prompts instance
270 */
271 private function get_llms_txt_prompts(): LLMs_Txt_Prompts {
272 if (!$this->llms_txt_prompts) {
273 // Ensure LLMs.txt Prompts is loaded
274 if (!class_exists('ThinkRank\\AI\\Prompts\\LLMs_Txt_Prompts')) {
275 require_once THINKRANK_PLUGIN_DIR . 'includes/ai/prompts/class-llms-txt-prompts.php';
276 }
277 $this->llms_txt_prompts = new LLMs_Txt_Prompts();
278 }
279 return $this->llms_txt_prompts;
280 }
281
282 /**
283 * Get Content Brief Prompts instance
284 *
285 * @since 1.0.0
286 *
287 * @return Content_Brief_Prompts Content Brief Prompts instance
288 */
289 private function get_content_brief_prompts(): Content_Brief_Prompts {
290 if (!$this->content_brief_prompts) {
291 // Ensure Content Brief Prompts is loaded
292 if (!class_exists('ThinkRank\\AI\\Prompts\\Content_Brief_Prompts')) {
293 require_once THINKRANK_PLUGIN_DIR . 'includes/ai/prompts/class-content-brief-prompts.php';
294 }
295 $this->content_brief_prompts = new Content_Brief_Prompts();
296 }
297 return $this->content_brief_prompts;
298 }
299 }
300