=== Lyzerslab AI Blog Automation ===
Requires at least: 5.5
Requires PHP: 7.4
Tested up to: 7.0
Stable tag: 2.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: ai, automation, markdown, blog, post submission
Contributors: zk-rana

Allow AI agents to submit blog posts via a frontend form or REST API with Markdown support, API key auth, tags, excerpts, and SEO meta.

== Description ==

Lyzerslab AI Blog Automation bridges the gap between AI agents and your WordPress blog. Agents can publish posts through a beautifully styled frontend form or directly via the REST API.

**Phase 1 — Security + API Foundation**

*   **API Key Authentication**: Generate and manage multiple named API keys. All REST API submissions require a valid key via `X-Lyzerslab-Key` header or `api_key` query parameter.
*   **Post Status Control**: Choose whether submissions are published immediately, saved as drafts, or queued for pending review.
*   **Enhanced Logging**: Every log entry now records the submission source (form vs API) and the request IP address for full audit trails.

**Phase 2 — AI Content Quality**

*   **Featured Image from Markdown**: The first `![alt](url)` in the post body is automatically sideloaded as the featured image. An explicit URL field is also available.
*   **Tags Support**: Pass a comma-separated list of tags on form or via API.
*   **Excerpt Support**: Custom post excerpts via form and API.
*   **SEO Meta**: Submit SEO title and meta description — stored in native Yoast (`_yoast_wpseo_*`) and Rank Math (`rank_math_*`) fields, plus a plugin-native fallback.

**Core Features**

*   **REST API Endpoint** at `/wp-json/lyzerslab/v1/submit` (POST, JSON body)
*   **Frontend Submission Form** via `[lyzerslab_post_submission]` shortcode
*   **Markdown Parser**: Headings, Bold/Italic/Strikethrough, Lists, Code (inline + fenced blocks), Blockquotes, Links, Images, Horizontal Rules
*   **Multi-Category Support**: Admin controls which categories appear on the form
*   **Beautiful Admin UI**: Modern card-based design with stats dashboard on the logs page
*   **Internationalization-ready**: Full i18n support

== Installation ==

1.  Upload the `lyzerslab-ai-blog-automation` folder to `/wp-content/plugins/`.
2.  Activate via the "Plugins" menu.
3.  Go to **Lyzer Automations → API Keys** and generate a key for your agent.
4.  Configure author, post status, and categories under **Lyzer Automations → Settings**.

== REST API ==

**Endpoint:** `POST /wp-json/lyzerslab/v1/submit`

**Headers:**
`X-Lyzerslab-Key: llk_your_key_here`
`Content-Type: application/json`

**Body (all except title + body are optional):**

```json
{
  "title": "Post Title",
  "body": "# Markdown body",
  "excerpt": "Short summary",
  "tags": "ai, automation",
  "categories": [1, 3],
  "image_url": "https://example.com/hero.jpg",
  "seo_title": "Custom SEO Title",
  "seo_description": "Meta description for search engines"
}
```

**Response:**
```json
{ "success": true, "post_id": 42, "post_url": "https://yoursite.com/post-title" }
```

== Frequently Asked Questions ==

= Is API key authentication required? =
For the REST API endpoint, yes — a valid active key must be sent. The frontend form uses a WordPress nonce instead.

= What post statuses can I use? =
`publish`, `draft`, or `pending` — configurable in settings per-site. The API or form always uses whichever status is configured.

= Which SEO plugins are supported? =
SEO meta is written to Yoast SEO (`_yoast_wpseo_title`, `_yoast_wpseo_metadesc`) and Rank Math (`rank_math_title`, `rank_math_description`) fields simultaneously, plus a plugin-native meta key as fallback.

= How does featured image sideloading work? =
If an `image_url` is provided (or an `![alt](url)` image exists in the Markdown body), the plugin uses WordPress's `media_sideload_image()` to download and attach it as the post thumbnail.

= What Markdown is supported? =
Headings (H1–H6), bold, italic, bold+italic, strikethrough, unordered/ordered lists, fenced code blocks (```), inline code, blockquotes, links, images, and horizontal rules.

== Screenshots ==
1.  **Settings Page** — Author, post status, fallback category, and form category configuration.
2.  **API Keys Page** — Generate, enable/disable, copy, and delete API keys.
3.  **Logs Page** — Stats overview and full audit log with source and IP.
4.  **Frontend Form** — Clean submission form with Markdown editor, tags, categories, featured image, and SEO fields.

== Changelog ==

= 2.0.0 =
*   Added: API Key authentication system (generate, manage, enable/disable, delete keys).
*   Added: REST API endpoint `POST /wp-json/lyzerslab/v1/submit` accepting JSON body.
*   Added: Post status control (publish / draft / pending) in settings.
*   Added: Request source (form/api) and IP address recorded in every log entry.
*   Added: Tags support via form field and API `tags` parameter.
*   Added: Excerpt support via form field and API `excerpt` parameter.
*   Added: SEO meta (title + description) — writes to Yoast, Rank Math, and native meta.
*   Added: Featured image sideloading from explicit URL or auto-detected from first Markdown image.
*   Added: Fenced code blocks (```), strikethrough (~~), H4–H6, horizontal rules in Markdown parser.
*   Added: Beautiful admin UI with stats dashboard on logs page.
*   Added: Admin and frontend CSS assets (enqueued, not inline).
*   Added: API Keys dedicated admin page.
*   Changed: Logs now show source, IP, and colour-coded rows.
*   Changed: Log limit raised to 300 entries.
*   Improved: IP detection supports Cloudflare and reverse proxies.

= 1.1.3 =
* WordPress 7.0 compatibility

= 1.1.2 =
*   Added: Multi-category settings so admins can choose which categories appear on the submission form.
*   Added: Category selection field on the frontend form.

= 1.0.2 =
*   Fixed: Replaced deprecated `get_page_by_title()` with `WP_Query` for WordPress 6.2+ compatibility.
*   Fixed: Corrected text domain to match plugin slug.

= 1.0.1 =
*   Initial release.

== Upgrade Notice ==

= 2.0.0 =
Major feature release. After upgrading, go to Lyzer Automations → API Keys to generate a key before using the REST API.