url
*/
public static function internal_links( $topic, $limit = 10, $exclude = 0 ) {
$out = array();
$exclude = (int) $exclude;
// One extra row instead of an exclusion clause: the excluded post is skipped here.
$query = new WP_Query(
array(
's' => wp_trim_words( $topic, 6, '' ),
'post_type' => array( 'post', 'page' ),
'post_status' => 'publish',
'posts_per_page' => $limit + 1,
'no_found_rows' => true,
)
);
$recent = count( $query->posts ) < $limit + 1 ? get_posts(
array(
'numberposts' => $limit + 1,
'post_status' => 'publish',
)
) : array();
foreach ( array_merge( $query->posts, $recent ) as $p ) {
if ( count( $out ) >= $limit ) {
break;
}
if ( (int) $p->ID !== $exclude ) {
$out[ get_the_title( $p ) ] = get_permalink( $p );
}
}
return $out;
}
/**
* Format link list for a prompt.
*
* @param array $links title => url.
* @return string
*/
private static function links_text( array $links ) {
$lines = array();
foreach ( $links as $t => $u ) {
$lines[] = '- ' . $t . ' → ' . $u;
}
return $lines ? implode( "\n", $lines ) : '(none)';
}
/**
* Plain-text excerpt of a post for prompts.
*
* @param WP_Post $post Post.
* @param int $words Max words.
* @return string
*/
public static function post_text( WP_Post $post, $words = 2500 ) {
$html = Aeoora_Content::render_html( $post, 'content' );
$md = Aeoora_Html_To_Markdown::convert( $html, get_permalink( $post ) );
return wp_trim_words( $md, $words, ' […]' );
}
/* ------------------------------------------------------- blog writer */
/**
* Step 1: outline (+ title, meta, answer capsule, takeaways, FAQ).
*
* @param array $in Input.
* @return array|WP_Error
*/
public static function outline( array $in ) {
$in = self::writer_input( $in );
$links = self::internal_links( $in['topic'], 8 );
$prompt = "Plan an AEO-optimised article.\n\n"
. 'Topic / primary question: ' . $in['topic'] . "\n"
. 'Focus phrase: ' . ( $in['keyword'] ? $in['keyword'] : $in['topic'] ) . "\n"
. 'Secondary keywords: ' . ( $in['keywords'] ? $in['keywords'] : '(choose naturally)' ) . "\n"
. 'Audience and intent: ' . ( $in['audience'] ? $in['audience'] : 'general readers' ) . '; intent = ' . $in['intent'] . "\n"
. 'Target length: about ' . $in['words'] . " words\n"
. 'First-hand experience to include: ' . ( $in['experience'] ? $in['experience'] : '(none provided — add [EXPERIENCE NEEDED] placeholders where it would help)' ) . "\n"
. 'Verified facts with sources (ONLY these may be stated as facts): ' . ( $in['facts'] ? $in['facts'] : '(none — use [STAT NEEDED] placeholders)' ) . "\n"
. "Internal pages available for links:\n" . self::links_text( $links ) . "\n\n"
. "Return JSON with exactly these keys:\n"
. "{\n \"title\": \"≤60 chars, main entity in the first 40 chars\",\n \"meta_description\": \"140–160 chars, core answer in the first 120\",\n \"slug\": \"short-url-slug\",\n \"entity\": \"main entity name used consistently\",\n \"answer\": \"40–60 word paragraph that directly answers the primary question and defines the entity (no links)\",\n \"takeaways\": [\"3–5 standalone facts, ≤25 words each\"],\n \"sections\": [{\"heading\": \"H2 text — about half phrased as real user questions\", \"brief\": \"what this section must answer, 1–2 sentences\", \"format\": \"paragraphs|list|steps|table|comparison\"}],\n \"faq\": [{\"q\": \"real follow-up question\", \"a\": \"30–60 word self-contained answer\"}],\n \"image_suggestions\": [{\"placement\": \"after which section\", \"alt\": \"descriptive alt text\"}]\n}\n"
. 'Use ' . max( 3, min( 12, (int) round( $in['words'] / 250 ) ) ) . ' sections covering the likely follow-up questions (definition, how it works, cost/time, steps, comparison/alternatives, pros/cons, mistakes) and end with a short "Bottom line" section. 3–6 FAQ items.';
$res = Aeoora_Ai::complete(
array(
'system' => self::system( 'You plan articles that get cited by AI answer engines.' ),
'prompt' => $prompt,
'json' => true,
'provider' => $in['provider'],
'model' => $in['model'],
)
);
if ( is_wp_error( $res ) ) {
return $res;
}
$data = $res['data'];
if ( empty( $data['sections'] ) || ! is_array( $data['sections'] ) ) {
return new WP_Error( 'aeoora_ai_bad_json', __( 'The AI’s plan came back without any sections. Try again, or choose a shorter length.', 'aeoora' ) );
}
$data['links'] = $links;
$data['_ai'] = array(
'provider' => $res['provider'],
'label' => isset( $res['provider_label'] ) ? $res['provider_label'] : $res['provider'],
'model' => $res['model'],
);
return self::normalize_outline( $data );
}
/**
* Step 2: write one section as HTML.
*
* @param array $in Input: outline, index, plus writer inputs.
* @return array|WP_Error { html }
*/
public static function section( array $in ) {
$w = self::writer_input( $in );
$outline = isset( $in['outline'] ) && is_array( $in['outline'] ) ? self::normalize_outline( $in['outline'] ) : array();
$i = isset( $in['index'] ) ? (int) $in['index'] : 0;
if ( empty( $outline['sections'][ $i ] ) ) {
return new WP_Error( 'aeoora_bad_section', __( 'Unknown section.', 'aeoora' ) );
}
$sec = $outline['sections'][ $i ];
$all = array();
foreach ( $outline['sections'] as $n => $s ) {
$all[] = ( $n + 1 ) . '. ' . $s['heading'] . ( $n === $i ? ' ← WRITE THIS ONE' : '' );
}
$count = max( 1, count( $outline['sections'] ) );
$target = max( 120, (int) round( ( $w['words'] - 150 ) / $count ) );
$links = isset( $outline['links'] ) && is_array( $outline['links'] ) ? $outline['links'] : array();
$prompt = 'Article title: ' . $outline['title'] . "\n"
. 'Main entity: ' . $outline['entity'] . "\n"
. 'Answer already given in the intro: ' . $outline['answer'] . "\n\n"
. "Full outline:\n" . implode( "\n", $all ) . "\n\n"
. 'Write ONLY section ' . ( $i + 1 ) . ': "' . $sec['heading'] . '" (about ' . $target . " words).\n"
. 'What it must cover: ' . $sec['brief'] . "\n"
. 'Preferred format: ' . $sec['format'] . "\n"
. 'Verified facts you may use: ' . ( $w['facts'] ? $w['facts'] : '(none — use [STAT NEEDED: …] placeholders)' ) . "\n"
. 'First-hand experience notes: ' . ( $w['experience'] ? $w['experience'] : '(none)' ) . "\n"
. "Internal pages you may link to with descriptive anchor text (max 2 in this section, only if relevant):\n" . self::links_text( $links ) . "\n\n"
. "Rules: start with
containing the heading exactly; the first paragraph answers the heading in ≤50 words and names its subject (never start with It/This/They); then detail in short paragraphs; use
/ for lists and steps,
with for comparisons; use
for sub-points; do not repeat the intro; do not add a conclusion unless this is the last section.\n"
. 'Output clean HTML only (h2, h3, p, ul, ol, li, table, thead, tbody, tr, th, td, blockquote, strong, em, a). No markdown, no code fences, no or .';
$res = Aeoora_Ai::complete(
array(
'system' => self::system(),
'prompt' => $prompt,
'provider' => $w['provider'],
'model' => $w['model'],
'max_tokens' => max( 1200, $target * 3 ),
)
);
if ( is_wp_error( $res ) ) {
return $res;
}
return array( 'html' => self::clean_html( $res['text'] ) );
}
/**
* Step 3: assemble and create a draft post.
*
* @param array $in Input: outline, sections (html[]), post_type, status.
* @return array|WP_Error { post_id, edit_url }
*/
public static function create_draft( array $in ) {
$outline = isset( $in['outline'] ) && is_array( $in['outline'] ) ? self::normalize_outline( $in['outline'] ) : array();
$sections = isset( $in['sections'] ) ? (array) $in['sections'] : array();
if ( empty( $outline['title'] ) ) {
return new WP_Error( 'aeoora_no_outline', __( 'Missing outline.', 'aeoora' ) );
}
if ( isset( $in['content'] ) && is_string( $in['content'] ) && '' !== trim( wp_strip_all_tags( $in['content'] ) ) ) {
// The article as edited in AI Studio's editor (intro, takeaways and sections included).
$html = self::clean_html( $in['content'] );
} else {
$html = '
\n\n\n";
break;
case 'hr':
$out .= "\n\n\n\n";
break;
default:
$out .= "\n" . $outer . "\n\n\n";
}
}
return trim( $out );
}
/**
* Editor: one AI action on one block of the article (rewrite, expand …).
*
* @param array $in Input: action, html, title, before, after, instruction, provider, model.
* @return array|WP_Error { html, truncated }
*/
public static function block_action( array $in ) {
$tasks = array(
'rewrite' => 'Rewrite this block with fresh wording. Keep its length, meaning and block type.',
'improve' => 'Improve its clarity and flow. Keep its length, meaning and block type.',
'expand' => 'Expand it with more useful, specific detail, about twice as long. You may return a few paragraphs or add a list.',
'shorten' => 'Shorten it to about half its length, keeping the key facts. Keep the block type.',
'simplify' => 'Rewrite it in plain language a 12-year-old understands. Keep the facts and the block type.',
'grammar' => 'Fix spelling, grammar and punctuation only. Change nothing else.',
'answer_first' => 'Rewrite it so the first sentence directly answers the question or states the main point in 25 words or fewer, naming its subject, then give the details.',
'example' => 'Return the block unchanged, followed by one short, concrete example paragraph that illustrates it.',
'list' => 'Turn it into a list: if it describes steps in order, otherwise
. Keep every fact.',
'continue' => 'Write the next one or two paragraphs that naturally follow this block. Do not repeat it.',
'write' => 'Write this part of the article: %s. It must fit naturally between the text before and after it.',
);
$action = isset( $in['action'] ) ? sanitize_key( (string) $in['action'] ) : '';
if ( ! isset( $tasks[ $action ] ) ) {
return new WP_Error( 'aeoora_bad_action', __( 'Unknown AI action.', 'aeoora' ), array( 'status' => 400 ) );
}
$html = isset( $in['html'] ) ? self::clean_html( substr( (string) $in['html'], 0, 12000 ) ) : '';
$instruction = isset( $in['instruction'] ) ? sanitize_textarea_field( substr( (string) $in['instruction'], 0, 500 ) ) : '';
$title = isset( $in['title'] ) ? sanitize_text_field( (string) $in['title'] ) : '';
$before = isset( $in['before'] ) ? sanitize_textarea_field( substr( (string) $in['before'], 0, 1500 ) ) : '';
$after = isset( $in['after'] ) ? sanitize_textarea_field( substr( (string) $in['after'], 0, 1500 ) ) : '';
if ( 'write' === $action && '' === $instruction ) {
return new WP_Error( 'aeoora_bad_action', __( 'Describe what the block should say.', 'aeoora' ), array( 'status' => 400 ) );
}
if ( 'write' !== $action && '' === trim( wp_strip_all_tags( $html ) ) ) {
return new WP_Error( 'aeoora_bad_action', __( 'This block is empty. Write something first, or use “Ask AI to write”.', 'aeoora' ), array( 'status' => 400 ) );
}
$task = 'write' === $action ? sprintf( $tasks['write'], $instruction ) : $tasks[ $action ];
$prompt = ( '' !== $title ? 'Article title: ' . $title . "\n" : '' )
. ( '' !== $before ? "Text just before:\n" . $before . "\n\n" : '' )
. ( '' !== $after ? "Text just after:\n" . $after . "\n\n" : '' )
. ( 'write' === $action ? '' : "The block (HTML):\n" . $html . "\n\n" )
. 'Task: ' . $task . "\n"
. "Rules: same language as the article; keep links that are already there; never invent statistics, quotes, studies or sources (write a [STAT NEEDED: …] placeholder instead); no introduction or commentary about what you changed.\n"
. 'Output clean HTML only (p, h2, h3, ul, ol, li, table, thead, tbody, tr, th, td, blockquote, strong, em, a). No Markdown, no code fences.';
$res = Aeoora_Ai::complete(
array(
'system' => self::system(),
'prompt' => $prompt,
'provider' => isset( $in['provider'] ) ? sanitize_key( (string) $in['provider'] ) : '',
'model' => isset( $in['model'] ) ? sanitize_text_field( (string) $in['model'] ) : '',
'max_tokens' => in_array( $action, array( 'expand', 'continue', 'write', 'example' ), true ) ? 2500 : 1500,
)
);
if ( is_wp_error( $res ) ) {
return $res;
}
$out = self::clean_html( $res['text'] );
if ( '' === trim( wp_strip_all_tags( $out ) ) ) {
return new WP_Error( 'aeoora_ai_empty', __( 'The AI returned nothing usable. Try again.', 'aeoora' ) );
}
if ( false === strpos( $out, '<' ) ) {
$out = wpautop( $out ); // Plain text: one paragraph per blank-line-separated chunk.
}
return array(
'html' => $out,
'truncated' => ! empty( $res['truncated'] ),
);
}
/* ------------------------------------------------------ post helpers */
/**
* Run a per-post task.
*
* @param string $task meta|faq|tldr|intro|headings|fixes|refresh.
* @param int $post_id Post ID.
* @param array $opts Options (provider, model, audit).
* @return array|WP_Error
*/
public static function for_post( $task, $post_id, array $opts = array() ) {
$post = get_post( $post_id );
if ( ! $post ) {
return new WP_Error( 'aeoora_no_post', __( 'Post not found.', 'aeoora' ) );
}
$text = self::post_text( $post );
$title = get_the_title( $post );
$kw = Aeoora_Seo::get_focus_keyword( $post->ID );
$ctx = 'Title: ' . $title . "\nURL: " . get_permalink( $post ) . ( $kw ? "\nFocus phrase: " . $kw : '' ) . "\n\nContent (Markdown):\n" . $text;
$common = array(
'provider' => isset( $opts['provider'] ) ? sanitize_key( $opts['provider'] ) : '',
'model' => isset( $opts['model'] ) ? sanitize_text_field( $opts['model'] ) : '',
'system' => self::system(),
'json' => true,
'context' => isset( $opts['context'] ) ? $opts['context'] : 'manual',
);
switch ( $task ) {
case 'meta':
$others = array_filter(
get_posts( array( 'numberposts' => 16 ) ),
static function ( $p ) use ( $post ) {
return (int) $p->ID !== (int) $post->ID;
}
);
$existing = wp_list_pluck( array_slice( $others, 0, 15 ), 'post_title' );
$prompt = "Write 3 SEO title options (each 50–60 characters) and 3 meta descriptions (each 140–160 characters, core answer within the first 120) for the page below.\nRules: front-load the main entity; state the concrete answer or benefit (include a number if the page has one); active voice; no quotes, emoji, ALL CAPS or keyword repetition; no claims the page does not support; no 'Click here' or 'Learn more'; must differ from these other titles on the site: " . implode( ' | ', $existing ) . "\nReturn JSON {\"titles\":[{\"text\":\"…\",\"chars\":0}],\"descriptions\":[{\"text\":\"…\",\"chars\":0}]} and verify the character counts.\n\n" . $ctx;
break;
case 'faq':
$prompt = "Write 4–6 FAQ items for the page below: real follow-up questions people ask an AI assistant after the page's main question (not questions already answered in a heading). Each answer is 40–80 words, self-contained, names its subject, and uses only facts from the page (or a [SOURCE NEEDED] placeholder).\nReturn JSON {\"faq\":[{\"q\":\"…\",\"a\":\"…\"}]}.\n\n" . $ctx;
break;
case 'tldr':
$prompt = "Write a TL;DR for the page below: a 40–60 word answer paragraph that directly answers the main question and defines the main entity, plus 3–5 key takeaways (≤25 words each, standalone facts from the page only).\nReturn JSON {\"tldr\":\"…\",\"takeaways\":[\"…\"]}.\n\n" . $ctx;
break;
case 'intro':
$prompt = "Rewrite the opening of the page below as an 'answer capsule': 40–60 words; the first sentence directly answers the main question and defines the entity (\"X is …\"); include one concrete number from the page if available; no links; no 'In this article'. Keep the author's voice.\nReturn JSON {\"intro\":\"…\",\"why\":\"≤25 words\"}.\n\n" . $ctx;
break;
case 'headings':
$prompt = "Suggest better H2/H3 headings for the page below. Rewrite up to half of them as the natural questions people ask (What/How/Why/Which/Can…); keep the others descriptive. Do not invent new topics.\nReturn JSON {\"headings\":[{\"before\":\"exact current heading\",\"after\":\"…\"}]}.\n\n" . $ctx;
break;
case 'refresh':
$prompt = "List what should be refreshed on the page below to make it current for " . wp_date( 'Y' ) . ": outdated facts, statistics, dates, product names, prices, missing recent developments. Use placeholders instead of guessing new numbers.\nReturn JSON {\"items\":[{\"what\":\"…\",\"why\":\"…\",\"suggestion\":\"…\"}]}.\n\n" . $ctx;
break;
case 'fixes':
default:
$audit = isset( $opts['audit'] ) ? $opts['audit'] : Aeoora_Audit::score_post( $post, 'content' );
$fails = array();
foreach ( (array) ( isset( $audit['checks'] ) ? $audit['checks'] : array() ) as $c ) {
if ( 'pass' !== $c['status'] ) {
$fails[] = array(
'check_id' => $c['id'],
'weight' => $c['max'],
'problem' => $c['message'],
'guide' => $c['fix'],
);
}
}
usort(
$fails,
static function ( $a, $b ) {
return $b['weight'] - $a['weight'];
}
);
$links = self::internal_links( $title, 6, $post->ID );
$prompt = "You are an AEO editor. Below is an audit of failed checks (sorted by weight) and the post. Propose the smallest edits that fix the highest-weight failures first. Never invent facts; use placeholders where data is missing. Preserve the author's voice and all factual claims.\n\nAudit: " . wp_json_encode( array_slice( $fails, 0, 10 ) ) . "\n\nInternal pages you may suggest linking:\n" . self::links_text( $links ) . "\n\n" . $ctx . "\n\nReturn JSON {\"summary\":\"one sentence\",\"fixes\":[{\"check_id\":\"…\",\"problem\":\"≤20 words\",\"fix_type\":\"rewrite|insert|delete|setting\",\"location\":\"after H1|section '
'|…\",\"before\":\"exact original snippet or null\",\"after\":\"replacement text/HTML\",\"why\":\"≤25 words\"}],\"intro\":\"40–60 word answer capsule\",\"meta_title\":\"50–60 chars\",\"meta_description\":\"140–160 chars\",\"faq\":[{\"q\":\"…\",\"a\":\"…\"}]}. Max 8 fixes.";
break;
}
$common['prompt'] = $prompt;
$res = Aeoora_Ai::complete( $common );
if ( is_wp_error( $res ) ) {
return $res;
}
$res['data']['_ai'] = array(
'provider' => $res['provider'],
'label' => isset( $res['provider_label'] ) ? $res['provider_label'] : $res['provider'],
'model' => $res['model'],
);
return $res['data'];
}
/**
* Content ideas based on the site's existing content.
*
* @param array $opts Options.
* @return array|WP_Error
*/
public static function ideas( array $opts = array() ) {
$titles = wp_list_pluck( get_posts( array( 'numberposts' => 40, 'post_status' => 'publish' ) ), 'post_title' );
$cats = get_terms(
array(
'taxonomy' => 'category',
'hide_empty' => true,
'number' => 15,
'orderby' => 'count',
'order' => 'DESC',
'fields' => 'names',
)
);
$prompt = "Suggest 6 new article ideas for this website that are likely to be cited by AI answer engines. Each idea answers a specific question real people ask ChatGPT, Perplexity or Google AI Mode, fills a gap in the existing content, and is not a duplicate.\nCategories: " . ( is_array( $cats ) ? implode( ', ', $cats ) : '' ) . "\nExisting titles:\n- " . implode( "\n- ", $titles ) . "\n\nReturn JSON {\"ideas\":[{\"title\":\"≤60 chars\",\"question\":\"the main question\",\"intent\":\"informational|commercial|how-to|comparison\",\"keyword\":\"focus phrase\",\"why\":\"≤25 words\"}]}.";
$res = Aeoora_Ai::complete(
array(
'system' => self::system( 'You are a content strategist.' ),
'prompt' => $prompt,
'json' => true,
'provider' => isset( $opts['provider'] ) ? $opts['provider'] : '',
'context' => isset( $opts['context'] ) ? $opts['context'] : 'manual',
)
);
if ( is_wp_error( $res ) ) {
return $res;
}
return isset( $res['data']['ideas'] ) ? (array) $res['data']['ideas'] : ( isset( $res['data']['items'] ) ? (array) $res['data']['items'] : array() );
}
/* -------------------------------------------------------- templates */
/**
* Template library.
*
* @return array id => template
*/
public static function templates() {
$t = array();
$f = static function ( $name, $label, $type = 'text', $placeholder = '' ) {
return array(
'name' => $name,
'label' => $label,
'type' => $type,
'placeholder' => $placeholder,
);
};
$topic = $f( 'topic', __( 'Topic or question', 'aeoora' ), 'text', __( 'e.g. How long does a heat pump last?', 'aeoora' ) );
$content = $f( 'content', __( 'Your text', 'aeoora' ), 'textarea' );
$product = $f( 'product', __( 'Product name', 'aeoora' ) );
$details = $f( 'details', __( 'Key details / facts', 'aeoora' ), 'textarea' );
$audience = $f( 'audience', __( 'Audience (optional)', 'aeoora' ) );
$business = $f( 'business', __( 'Business name', 'aeoora' ) );
$location = $f( 'location', __( 'City / area', 'aeoora' ) );
$defs = array(
// AEO.
array( 'ai_overview_answer', 'aeo', __( 'AI Overview answer builder', 'aeoora' ), __( 'A 40–60 word, quotable answer-first paragraph for a question.', 'aeoora' ), array( $topic, $details ), 'Write a 40–60 word answer capsule for: {topic}. First sentence answers directly and defines the subject. Include one concrete number only if it is in these facts: {details}. Then add 3 bullet key facts.' ),
array( 'faq_generator', 'aeo', __( 'FAQ generator', 'aeoora' ), __( 'Follow-up questions with self-contained answers.', 'aeoora' ), array( $topic, $details ), 'Write 6 FAQ items (question + 40–80 word self-contained answer) about {topic}, using only these facts: {details}. Format: **Q:** … then answer.' ),
array( 'paa_questions', 'aeo', __( 'Questions people ask AI', 'aeoora' ), __( 'The prompts real users type into ChatGPT/Perplexity about a topic.', 'aeoora' ), array( $topic, $audience ), 'List 20 realistic questions {audience} ask AI assistants about {topic}, grouped by intent (definition, how-to, cost, comparison, problems). One per line.' ),
array( 'definition_box', 'aeo', __( 'Definition box', 'aeoora' ), __( 'A crisp “X is…” definition plus context.', 'aeoora' ), array( $topic ), 'Write a definition of {topic}: one sentence "X is …", then 2 sentences of context, then "Also called:" with common aliases.' ),
array( 'key_takeaways', 'aeo', __( 'Key takeaways', 'aeoora' ), __( '3–5 standalone takeaway bullets from your text.', 'aeoora' ), array( $content ), "Write 3–5 key takeaways (≤25 words each, standalone facts) from this text only:\n{content}" ),
array( 'tldr', 'aeo', __( 'TL;DR summary', 'aeoora' ), __( 'Answer-first summary of any text.', 'aeoora' ), array( $content ), "Summarise in a 40–60 word TL;DR that leads with the answer:\n{content}" ),
array( 'featured_snippet_list', 'aeo', __( 'Step-by-step list snippet', 'aeoora' ), __( 'Numbered steps that answer a how-to.', 'aeoora' ), array( $topic, $details ), 'Write a one-sentence answer and then 5–8 numbered steps (one action each, ≤20 words) for: {topic}. Facts: {details}' ),
array( 'comparison_table', 'aeo', __( 'Comparison table', 'aeoora' ), __( 'A Markdown table comparing options.', 'aeoora' ), array( $f( 'items', __( 'Items to compare', 'aeoora' ) ), $f( 'criteria', __( 'Criteria (optional)', 'aeoora' ) ), $details ), 'Create a Markdown comparison table of {items} by {criteria}. Use only these facts: {details}; mark unknown cells [NEEDS DATA]. Add a 2-sentence verdict after the table.' ),
array( 'pros_cons', 'aeo', __( 'Pros and cons', 'aeoora' ), __( 'Balanced pros/cons list.', 'aeoora' ), array( $topic, $details ), 'Write a balanced pros and cons list (5 each) for {topic}, using these facts: {details}. End with "Best for:" and "Not for:".' ),
array( 'voice_answer', 'aeo', __( 'Voice search answer', 'aeoora' ), __( 'A 20–30 second spoken answer.', 'aeoora' ), array( $topic ), 'Write a natural spoken answer (about 50 words, 20–30 seconds) to: {topic}.' ),
array( 'entity_glossary', 'aeo', __( 'Glossary / entities', 'aeoora' ), __( 'Key terms and one-line definitions.', 'aeoora' ), array( $topic ), 'List the 12 most important terms/entities for {topic} with one-line plain definitions.' ),
array( 'stat_placeholders', 'aeo', __( 'Statistics to research', 'aeoora' ), __( 'Which data points would strengthen a page (no invented numbers).', 'aeoora' ), array( $topic ), 'List 10 statistics or data points that would make an article about {topic} more citable, with the type of primary source to find each one. Do NOT invent any numbers.' ),
array( 'content_brief', 'aeo', __( 'AEO content brief', 'aeoora' ), __( 'Brief for a writer: questions, entities, structure.', 'aeoora' ), array( $topic, $audience ), 'Create an AEO content brief for {topic} for {audience}: main question, answer capsule guidance, 8 sub-questions for H2s, entities to mention, data to source, internal link ideas, FAQ ideas, schema to add.' ),
// Blog.
array( 'blog_outline', 'blog', __( 'Blog outline', 'aeoora' ), __( 'Question-led outline.', 'aeoora' ), array( $topic, $audience ), 'Create a blog outline for {topic} ({audience}): title, answer capsule, 6–10 H2s (about half as questions) with 2–3 bullet points each, FAQ ideas.' ),
array( 'blog_intro', 'blog', __( 'Answer-first intro', 'aeoora' ), __( 'Opening paragraph that answers immediately.', 'aeoora' ), array( $topic, $details ), 'Write an answer-first intro (40–60 words) for an article about {topic}. Facts: {details}' ),
array( 'blog_conclusion', 'blog', __( 'Bottom line', 'aeoora' ), __( 'A short, useful conclusion.', 'aeoora' ), array( $content ), "Write a 2–4 sentence 'Bottom line' that restates the answer and the key number from:\n{content}" ),
array( 'title_ideas', 'blog', __( 'Title ideas', 'aeoora' ), __( '10 titles (≤60 chars), many as questions.', 'aeoora' ), array( $topic ), 'Write 10 article titles (≤60 characters) for {topic}; at least 5 phrased as questions people ask.' ),
array( 'listicle', 'blog', __( 'Listicle', 'aeoora' ), __( 'A numbered “X ways/tips” article.', 'aeoora' ), array( $topic, $details ), 'Write a listicle about {topic}: answer capsule, then 7–10 numbered items each with a bold one-line summary and 2–3 sentences. Facts: {details}' ),
array( 'how_to_guide', 'blog', __( 'How-to guide', 'aeoora' ), __( 'Step-by-step tutorial.', 'aeoora' ), array( $topic, $details ), 'Write a how-to guide for {topic}: what you need, numbered steps, common mistakes, FAQ. Facts: {details}' ),
array( 'expand_paragraph', 'blog', __( 'Expand a paragraph', 'aeoora' ), __( 'Add depth without fluff.', 'aeoora' ), array( $content ), "Expand this into 2–3 tight paragraphs with an example; no fluff, no invented facts:\n{content}" ),
array( 'case_study', 'blog', __( 'Case study outline', 'aeoora' ), __( 'Challenge → approach → results structure.', 'aeoora' ), array( $topic, $details ), 'Outline a case study about {topic}: challenge, approach, results (only from these facts: {details}), quote placeholder, lessons.' ),
// SEO.
array( 'meta_description', 'seo', __( 'Meta description', 'aeoora' ), __( '3 options, 140–160 characters.', 'aeoora' ), array( $topic, $details ), 'Write 3 meta descriptions (140–160 chars, answer in the first 120) for a page about {topic}. Facts: {details}. Show the character count of each.' ),
array( 'seo_title', 'seo', __( 'SEO title', 'aeoora' ), __( '5 options, 50–60 characters.', 'aeoora' ), array( $topic ), 'Write 5 SEO titles (50–60 chars, entity first) for {topic}. Show character counts.' ),
array( 'alt_text', 'seo', __( 'Image alt text', 'aeoora' ), __( 'Descriptive alt text for an image.', 'aeoora' ), array( $f( 'image', __( 'What the image shows', 'aeoora' ) ), $topic ), 'Write 3 alt text options (≤125 chars) for an image showing {image} in an article about {topic}.' ),
array( 'schema_jsonld', 'seo', __( 'Schema JSON-LD', 'aeoora' ), __( 'Draft JSON-LD for a page type.', 'aeoora' ), array( $f( 'type', __( 'Schema type (FAQPage, HowTo, Product…)', 'aeoora' ) ), $details ), 'Write valid schema.org JSON-LD of type {type} using only these details: {details}. Output only the JSON.' ),
array( 'internal_links', 'seo', __( 'Internal link ideas', 'aeoora' ), __( 'Anchor text and target ideas.', 'aeoora' ), array( $content ), "Suggest 6 internal link opportunities (anchor text → what the target page should be about) for:\n{content}" ),
array( 'keyword_clusters', 'seo', __( 'Topic clusters', 'aeoora' ), __( 'Pillar + cluster plan.', 'aeoora' ), array( $topic ), 'Create a topic cluster for {topic}: 1 pillar page and 12 cluster articles, each as a question with search intent.' ),
array( 'refresh_plan', 'seo', __( 'Content refresh plan', 'aeoora' ), __( 'What to update in an old post.', 'aeoora' ), array( $content ), "List what to refresh in this content to make it current (facts, dates, examples, missing sections). No invented numbers:\n{content}" ),
// Rewrite.
array( 'rewrite_clear', 'rewrite', __( 'Make it clearer', 'aeoora' ), __( 'Plain language, short sentences.', 'aeoora' ), array( $content ), "Rewrite in plain language with sentences under 20 words, keeping every fact:\n{content}" ),
array( 'rewrite_shorter', 'rewrite', __( 'Make it shorter', 'aeoora' ), __( 'Cut by ~40% without losing facts.', 'aeoora' ), array( $content ), "Shorten by about 40% without losing any facts:\n{content}" ),
array( 'rewrite_tone', 'rewrite', __( 'Change tone', 'aeoora' ), __( 'Rewrite in another tone.', 'aeoora' ), array( $content, $f( 'tone', __( 'Tone', 'aeoora' ), 'text', __( 'friendly, expert, formal…', 'aeoora' ) ) ), "Rewrite in a {tone} tone, keeping the facts:\n{content}" ),
array( 'fix_grammar', 'rewrite', __( 'Fix grammar', 'aeoora' ), __( 'Correct spelling and grammar only.', 'aeoora' ), array( $content ), "Correct spelling and grammar only; change nothing else:\n{content}" ),
array( 'translate', 'rewrite', __( 'Translate', 'aeoora' ), __( 'Translate naturally.', 'aeoora' ), array( $content, $f( 'language', __( 'Target language', 'aeoora' ) ) ), "Translate naturally into {language}, keeping formatting:\n{content}" ),
array( 'humanize', 'rewrite', __( 'Add first-hand voice', 'aeoora' ), __( 'Make text sound experienced (with placeholders for your own experience).', 'aeoora' ), array( $content ), "Rewrite to sound like an experienced practitioner. Where first-hand experience would help, insert [YOUR EXPERIENCE: …] placeholders instead of inventing it:\n{content}" ),
// E-commerce.
array( 'product_description', 'ecommerce', __( 'Product description', 'aeoora' ), __( 'AI-shopping-ready product copy.', 'aeoora' ), array( $product, $details, $audience ), 'Write a product description for {product} for {audience}: one-sentence answer of what it is and who it is for, 4–6 benefit bullets, a specs list from these details only: {details}, and 3 FAQ items.' ),
array( 'product_short', 'ecommerce', __( 'Short product summary', 'aeoora' ), __( 'One-paragraph summary for listings.', 'aeoora' ), array( $product, $details ), 'Write a 40–50 word product summary for {product}: what it is, who it is for, the key differentiator. Details: {details}' ),
array( 'product_faq', 'ecommerce', __( 'Product FAQ', 'aeoora' ), __( 'Buyer questions with answers.', 'aeoora' ), array( $product, $details ), 'Write 6 buyer FAQs (sizing, compatibility, shipping, care, warranty, comparison) for {product}; answer only from: {details}; otherwise say [CONFIRM WITH STORE].' ),
array( 'category_description', 'ecommerce', __( 'Category description', 'aeoora' ), __( 'Intro text for a shop category.', 'aeoora' ), array( $f( 'category', __( 'Category', 'aeoora' ) ), $details ), 'Write a 80–120 word category intro for {category} that answers "what should I buy and why", plus 3 buying-tip bullets. Details: {details}' ),
// Social & email.
array( 'linkedin_post', 'social', __( 'LinkedIn post', 'aeoora' ), __( 'Insightful post from your content.', 'aeoora' ), array( $content ), "Write a LinkedIn post (120–200 words) with a strong first line, 3 insights and a question at the end, based on:\n{content}" ),
array( 'x_thread', 'social', __( 'X / Threads thread', 'aeoora' ), __( '5–7 post thread.', 'aeoora' ), array( $content ), "Write a 6-post thread (≤270 chars each) based on:\n{content}" ),
array( 'newsletter', 'social', __( 'Newsletter email', 'aeoora' ), __( 'Email promoting a post.', 'aeoora' ), array( $content ), "Write a newsletter email (subject line, preview text, 120-word body, CTA) promoting:\n{content}" ),
array( 'youtube_description', 'social', __( 'YouTube description', 'aeoora' ), __( 'Description with chapters.', 'aeoora' ), array( $topic, $details ), 'Write a YouTube description for a video about {topic}: 2-sentence summary, chapter list placeholders, 5 key points. Details: {details}' ),
// Local & brand.
array( 'local_business', 'local', __( 'Local business description', 'aeoora' ), __( 'Who you are, where, for whom.', 'aeoora' ), array( $business, $location, $details ), 'Write a 100-word business description for {business} in {location}: what it does, for whom, service area, what makes it different. Only from: {details}' ),
array( 'about_page', 'local', __( 'About page', 'aeoora' ), __( 'Trust-building About page draft.', 'aeoora' ), array( $business, $details ), 'Draft an About page for {business}: who we are, what we do, credentials and experience (from: {details}), why trust us, contact. Use placeholders for missing facts.' ),
array( 'author_bio', 'local', __( 'Author bio', 'aeoora' ), __( 'E-E-A-T friendly author bio.', 'aeoora' ), array( $f( 'name', __( 'Name', 'aeoora' ) ), $details ), 'Write a 60–80 word author bio for {name} showing real experience and credentials from: {details}. Third person.' ),
array( 'press_release', 'local', __( 'Press release', 'aeoora' ), __( 'News release draft.', 'aeoora' ), array( $topic, $details ), 'Write a press release about {topic}: headline, dateline placeholder, answer-first lead, details from: {details}, quote placeholder, boilerplate placeholder.' ),
array( 'review_reply', 'local', __( 'Review reply', 'aeoora' ), __( 'Professional reply to a customer review.', 'aeoora' ), array( $content ), "Write a short, professional reply to this customer review:\n{content}" ),
);
foreach ( $defs as $d ) {
$t[ $d[0] ] = array(
'id' => $d[0],
'group' => $d[1],
'label' => $d[2],
'desc' => $d[3],
'fields' => $d[4],
'prompt' => $d[5],
);
}
return apply_filters( 'aeoora_ai_templates', $t );
}
/**
* Template groups.
*
* @return array
*/
public static function template_groups() {
return array(
'aeo' => __( 'AEO & answers', 'aeoora' ),
'blog' => __( 'Blog', 'aeoora' ),
'seo' => __( 'SEO', 'aeoora' ),
'rewrite' => __( 'Rewrite', 'aeoora' ),
'ecommerce' => __( 'E-commerce', 'aeoora' ),
'social' => __( 'Social & email', 'aeoora' ),
'local' => __( 'Brand & local', 'aeoora' ),
);
}
/**
* Run a template.
*
* @param string $id Template id.
* @param array $fields Field values.
* @param array $opts Options (provider, model).
* @return array|WP_Error { text }
*/
public static function run_template( $id, array $fields, array $opts = array() ) {
$all = self::templates();
if ( ! isset( $all[ $id ] ) ) {
return new WP_Error( 'aeoora_template', __( 'Unknown template.', 'aeoora' ) );
}
$tpl = $all[ $id ];
$prompt = $tpl['prompt'];
foreach ( $tpl['fields'] as $field ) {
$val = isset( $fields[ $field['name'] ] ) ? sanitize_textarea_field( (string) $fields[ $field['name'] ] ) : '';
$prompt = str_replace( '{' . $field['name'] . '}', '' !== $val ? $val : '(not specified)', $prompt );
}
$prompt .= "\n\nFormat the answer in clean Markdown.";
$res = Aeoora_Ai::complete(
array(
'system' => self::system(),
'prompt' => $prompt,
'provider' => isset( $opts['provider'] ) ? sanitize_key( $opts['provider'] ) : '',
'model' => isset( $opts['model'] ) ? sanitize_text_field( $opts['model'] ) : '',
)
);
if ( is_wp_error( $res ) ) {
return $res;
}
return array(
'text' => $res['text'],
'provider' => $res['provider'],
'label' => isset( $res['provider_label'] ) ? $res['provider_label'] : $res['provider'],
'model' => $res['model'],
);
}
}