=== Kaldia AEO Manager ===
Contributors: Kaldia Team
Tags: aeo, answer-engine-optimization, automatic-schema, seo-tool, json-ld
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 7.4
Stable tag: 1.0.5
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: kaldia-aeo-manager
Domain Path: /languages

AI-powered AEO plugin. Generate & inject FAQ / HowTo (plus Event & Product) JSON-LD schema. Rich results for Google & AI — no code.

== Description ==

**Answer Engine Optimization (AEO)** helps search engines and AI assistants deliver precise answers.  
**Kaldia AEO Manager** automates the creation and injection of **FAQ**, **HowTo**, **Event**, and **Product** schemas (schema.org) in **JSON-LD**, directly into your page `<head>` — one click, zero coding.

### Why AEO matters
Search engines (Google, Bing) and assistants (ChatGPT, Copilot, Siri…) look for **structured answers**. Adding JSON-LD schemas (FAQ, HowTo…) boosts your chances of:
* Getting **rich results** (expandable FAQ, step-by-step HowTo)
* Being cited as a **direct answer** by AI systems
* Improving overall visibility

### What Kaldia makes simple
* **AI generation (OpenAI only)**: pick a schema type, let the AI craft relevant Q/As (FAQ) or steps (HowTo).  
* **Advanced controls**: choose among 4 common OpenAI LLM models, set temperature and max tokens.  
* **Edit & validate**: tweak the JSON-LD in a modal and validate before publishing.  
* **Automatic injection**: the JSON-LD script is inserted into the page `<head>` (disable any time).  
* **Friendly interface**: clean, easy-to-use UI that follows WordPress UX standards.

### Key features
- Generate & inject **FAQ**, **HowTo**, **Event**, **Product** schemas (JSON-LD)  
- Single provider: **OpenAI**, with 4 selectable LLM models (e.g. gpt-4o, gpt-4, gpt-4o-mini, gpt-3.5-turbo)  
- Adjust **temperature** and **max tokens** per generation  
- Pick schema type per page + regenerate on demand  
- Built-in JSON-LD editor (validate & save)  
- Clean injection in each page `<head>`  
- Compliant with WordPress coding standards (REST API, permissions, i18n)

> **KALDIA = Knowledge & Language-Driven Intent Answers**  
> Our mission: make AEO simple and accessible.

---

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/` or install it via “Plugins → Add New”.  
2. Activate **Kaldia AEO Manager**.  
3. Open the **Kaldia AEO** menu in your WordPress admin.  
4. Click **Settings** to:  
   - enter your OpenAI API key,  
   - choose one of the 4 supported LLM models,  
   - set temperature and max tokens.  
5. In the pages list, pick a **schema type** (FAQ, HowTo, Event, Product), then click **Generate**.  
6. Edit/validate the JSON-LD, click **Save** — the script is injected into the `<head>`.  
7. You can disable or delete a schema at any time.

---

== Frequently Asked Questions ==

= What is Answer Engine Optimization (AEO)? =  
AEO is the practice of structuring content so search engines and AI assistants can return precise answers. JSON-LD schemas (FAQ, HowTo…) are a major lever.

= Does the plugin insert the code automatically? =  
Yes. After you save the JSON-LD, Kaldia injects it into the `<head>` of your page. You can remove it with one click.

= Why only OpenAI? =  
To keep things simple and reliable. Kaldia focuses on one provider with full control over model, temperature, and tokens. More providers may come later.

= Can I edit the generated FAQ or HowTo? =  
Absolutely. You review and edit the JSON-LD in a modal before publishing.

= Is it compatible with my page builder (Elementor, Divi, Gutenberg…)? =  
Yes. Kaldia works at the `<head>` level and doesn’t interfere with builders.

= Where are API keys stored? =  
In WordPress options. Only administrators can access them. You can change or remove them anytime.

= How do I remove a schema from a page? =  
Open the Kaldia editor for that page and click “Delete”. The script is removed from the `<head>`.

---

== Screenshots ==

1. **Kaldia Interface** – pages table, schema status, “Generate / Edit” actions.  
2. **OpenAI Settings Popup** – API key, model selector, temperature & tokens.  
3. **JSON-LD Edit Popup** – generated FAQ/HowTo JSON-LD, editable & validated.  
4. **Injected JSON-LD Example** – `<script type="application/ld+json">` visible in the page head (via browser dev tools).

---

== Changelog ==

= 1.0.5 =
* Performance: pre-load post meta in a single query on the pages list endpoint, eliminating N+1 database queries.

= 1.0.4 =
* Performance: decrypted API key is now cached in memory for the duration of the request, avoiding redundant database reads and OpenSSL decryption on repeated calls.
* Added cache invalidation on key update and deletion for consistency.

= 1.0.2 =  
* Performance optimization: prompt templates are now cached in-memory per request during generation.
* Reduced unnecessary database writes by avoiding model option updates during each generation call.
* Minor internal cleanup of OpenAI response handling to avoid redundant body parsing.

= 1.0.1 =  
* Fixed API responses to always return valid JSON
* Improved error handling in frontend API helper
* Prevented HTML leaks during content generation
* Added content length validation before AI processing
* Enhanced robustness against shortcode interference
* Better user feedback for generation failures

= 1.0.0 =  
* Initial public release.  
* AI generation (OpenAI) & injection of FAQ / HowTo / Event / Product JSON-LD.  
* Temperature & max tokens controls.  
* Friendly UI, JSON-LD editor, per-page delete & regenerate.

---

== Upgrade Notice ==

= 1.0.5 =
Pages list now pre-loads all post meta in one query instead of 2 per page.

= 1.0.4 =
Lightweight performance update: API key decryption is cached per request, reducing database queries and crypto overhead.

= 1.0.2 =
Minor optimization update improving generation performance and reducing unnecessary option writes.

= 1.0.1 =  
Important stability update - fixes JSON parsing errors and improves content generation reliability.

= 1.0.0 =  
First release — configure your OpenAI key and model, then start generating schemas.

---

== External services ==

This plugin uses the OpenAI API (api.openai.com) to validate the API key and to generate JSON-LD when an administrator requests it. For key validation, the API key is sent in the Authorization header to fetch available models. For generation, a prompt with minimal context from the selected post (title, headings, short excerpts) and the chosen parameters (model, max_tokens, temperature) is sent. No data is sent from the frontend, and nothing is transmitted unless an admin initiates it. The API key can be removed at any time in the settings.

OpenAI Terms of Use: https://openai.com/policies/terms-of-use  
OpenAI Privacy Policy: https://openai.com/policies/privacy-policy

---

== Privacy ==

Kaldia does not send any user data to third parties, except for the explicit calls you make to the OpenAI API. Those requests may include page content excerpts to generate JSON-LD.
