=== AI Auto Poster ===
Contributors: besoft, freemius
Tags: ai, content generator, scheduled posts, automation, image generator
Requires at least: 5.8
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 1.0.7
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Schedule and auto-publish AI-generated articles using external AI services, with image generation, similarity checks, retry control, and 7-day logs.

== Description ==

AI Auto Poster automates WordPress content creation with AI. Define prompts as tasks, schedule them by day and time, and publish generated articles automatically using the AI provider you configure.

The plugin can also generate featured images, check generated content for similarity against recent posts, retry generation up to your configured limit, and keep execution logs for up to 7 days.

= Features =

* Text generation using external AI providers such as Claude, OpenAI, Gemini, Mistral, Groq, DeepSeek, and OpenRouter.
* Featured image generation or selection using configured image providers and stock image services.
* Per-task scheduling with day-of-week and time settings.
* Missed schedule recovery with the original scheduled publish date/time preserved.
* Similarity detection using keyword scoring and optional AI scoring.
* Configurable retry control (1 to 10 attempts; default 3).
* Execution logs stored locally for up to 7 days.
* Encrypted API key storage using WordPress salts.
* SEO output: meta description, focus keyword, JSON-LD article schema, OGP, canonical URL, internal linking, table of contents, related posts, reading time, and image alt text.
* Optional integration with Yoast SEO, Rank Math, and All in One SEO.
* English and Japanese localization. Article generation supports approximately 50 languages.

= Important: Third-Party Services =

== License Management (Freemius) ==

This plugin uses the Freemius SDK to handle license validation, plan management, and software updates. The SDK is loaded on every administrator page load.

The Freemius SDK communicates with the Freemius servers (https://api.freemius.com and https://wp.freemius.com) to:

* Verify the active license and plan.
* Check for plugin updates.
* Process payments and license activation when upgrading to the Pro plan.
* Optionally collect anonymous usage statistics if the user opts in during installation.

Freemius is a third-party service. By using this plugin, the data described above may be transmitted to Freemius. For details, see:

* Freemius Terms of Service: https://freemius.com/terms/
* Freemius Privacy Policy: https://freemius.com/privacy/

== AI / Image / Stock Photo Services ==

The plugin connects to AI text providers, image providers, and stock photo providers only when you configure and enable them. The plugin does not send article content to external services unless an AI provider, image provider, or stock image provider is configured and used.

Depending on your settings, this plugin may send the following data to third-party services:

* Text prompts and task instructions.
* Generated article title and article content.
* Recent post titles and excerpts for similarity checking.
* Image prompts, article titles, slugs, and excerpts for featured image generation or image search.
* Style and language settings required to generate the requested output.

You must obtain your own API key or account for each provider you use. Please review the terms and privacy policies of the selected provider before using it.

External service documentation and policies:

* Anthropic Claude: https://www.anthropic.com/legal/privacy / https://www.anthropic.com/legal/consumer-terms
* OpenAI / DALL-E: https://openai.com/policies/privacy-policy / https://openai.com/policies/terms-of-use
* Google Gemini / Imagen: https://policies.google.com/privacy / https://ai.google.dev/terms
* Mistral AI: https://mistral.ai/terms/
* Groq: https://groq.com/privacy-policy/
* DeepSeek: https://chat.deepseek.com/downloads/DeepSeek%20Privacy%20Policy.html
* OpenRouter: https://openrouter.ai/privacy
* Stability AI: https://stability.ai/privacy-policy
* Black Forest Labs / Flux: https://blackforestlabs.ai/terms-of-service/
* Fal.ai: https://fal.ai/legal/privacy-policy
* Unsplash: https://unsplash.com/privacy
* Pixabay: https://pixabay.com/service/privacy/
* Pexels: https://www.pexels.com/privacy-policy/
* Openverse: https://wordpress.org/about/privacy/

== Optional Search Engine Notification ==

If you enable the "Sitemap ping" SEO option, the plugin will notify the IndexNow protocol when a new article is published, so search engines such as Bing and Yandex can index it faster. IndexNow requires a key file placed in your wp-content directory; without it, the ping is silently skipped. This option is OFF by default.

* IndexNow: https://www.indexnow.org/

= Privacy =

* API keys for AI / image / stock photo providers are stored in the WordPress database in encrypted form (AES-256-CBC using WordPress AUTH_KEY).
* Tasks, settings, retry information, and execution logs are stored locally in WordPress.
* Execution logs are automatically retained for up to 7 days.
* The plugin itself does not collect analytics or behavioral tracking. The bundled Freemius SDK may collect license/plan validation data and (if the user opts in) anonymous usage statistics. See "License Management (Freemius)" above for details.
* Generated posts and featured images remain in WordPress after uninstall.

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/ai-auto-poster/`, or install the plugin through the WordPress plugins screen.
2. Activate the plugin through the "Plugins" screen in WordPress.
3. Open "AI Auto Poster" from the WordPress admin menu.
4. Configure at least one text AI provider and save its API key.
5. Optionally configure an image provider or stock image provider.
6. Create a task with a prompt and a schedule.
7. The plugin runs via WP-Cron according to the configured schedule. We recommend keeping the post status as "Draft" for the first few articles so you can review the output before publishing.

== Frequently Asked Questions ==

A more comprehensive FAQ is available inside the plugin admin screen ("AI Auto Poster" > "FAQ"). The questions below cover the most common pre-installation questions.

= How much does it cost to use this plugin? =

The plugin itself is free for up to 10 published articles per month. The Pro plan removes the post limit and unlocks duplicate prevention, SEO output, and configurable missed-schedule recovery. In addition, the plugin uses external AI services that you pay separately with your own API key. Costs vary widely by provider; budget models such as Gemini Flash, Groq, and DeepSeek can produce a short article for a fraction of a cent, while premium models can cost several cents per article. Featured image generation is usually significantly more expensive per item than text generation.

= Is there a free trial of the Pro plan? =

Yes. A 7-day Pro trial is available from the plan card in the plugin dashboard and does not require a payment method to start.

= Will my article be published immediately, or can I review it first? =

You decide. The post status setting has three options: Draft, Pending Review, and Publish. The default is Draft, which is the safest option while you are tuning your prompts.

= Will Google penalize my site for AI-generated content? =

Google's published guidance is that AI assistance is acceptable as long as the resulting content is helpful, accurate, and original. To stay safe we recommend reviewing posts before publishing (use the Draft status), writing prompts that target specific useful topics, keeping similarity detection enabled to avoid near-duplicate posts, and editing AI output where it adds real value.

= Which AI provider should I choose? =

If you are not sure, Gemini Flash and Groq are good starting points because they offer free tiers and very low per-article cost. For higher article quality, Claude (Anthropic) and GPT-4 class models from OpenAI are popular choices. You can change the provider any time.

= What languages does the plugin support? =

About 50 languages including English, Japanese, Chinese (Simplified and Traditional), Korean, Spanish, French, German, Italian, Portuguese, Russian, Arabic, Hindi, and many European languages. The output language is set per task.

= Will the plugin work without WP-Cron? =

The plugin uses WordPress WP-Cron. WP-Cron only runs when someone visits the site, so on low-traffic sites scheduled posts can be delayed. We recommend asking your hosting provider to set up a real system cron that calls `wp-cron.php` every few minutes. Most managed WordPress hosts already do this.

= Are my API keys stored securely? =

Yes. API keys are encrypted using AES-256-CBC with the WordPress AUTH_KEY before being saved in the database. Keys are never written to execution logs and are never displayed in the admin UI after saving.

= Does the plugin send data to external servers? =

The plugin sends data to external services only when you configure and enable them, with two exceptions: (1) the Freemius SDK communicates with Freemius servers for license validation and update checks (always active), and (2) if you enable the optional sitemap ping feature, the plugin notifies IndexNow when a new article is published. See the "Important: Third-Party Services" section above for full details.

= What happens when I uninstall? =

Plugin settings, tasks, logs, encrypted API keys, transient cache, and the plugin's internal post metadata are removed. Generated articles themselves and their featured images in the Media Library are kept; your published content is never deleted by uninstall.

== Screenshots ==

1. Text AI provider settings.
2. Image provider settings.
3. Task and schedule settings.
4. Similarity detection settings.
5. Execution logs.

== Changelog ==

= 1.0.7 =
* Fixed: generated articles could come out much shorter than the requested character count, especially in Japanese and other multibyte languages. The plugin now verifies the generated body length after generation and automatically regenerates when it falls below the requested minimum, while still publishing the best result if all retries are exhausted (a slightly short article is preferred over no article).
* Fixed: when using OpenAI reasoning models (GPT-5, o3-mini) and equivalent reasoning models on other providers (Mistral, DeepSeek, OpenRouter), the article body could be empty or truncated because the model's hidden "thinking" consumed the output-token budget. The token budget is now raised for reasoning models so the body has room to complete.
* Fixed: a stray "}" or other leftover JSON characters could occasionally appear at the end of an article body when the AI returned malformed or truncated JSON. Such envelope leftovers are now removed from the body, with a safeguard that preserves legitimate braces in code articles.
* Fixed: with Google Gemini (and Anthropic Claude), long article bodies returned in multiple response parts were truncated to the first part. All parts are now concatenated so the full body is kept.
* Fixed: a Quick Post retry triggered by the new length check could incorrectly report "a Quick Post is already in progress in another tab." Retries now reuse the correct retry path and no longer collide with the start-of-run guard.
* Fixed: truncation detection for OpenAI-compatible providers now also recognizes alternate finish-reason spellings, so a cut-off response is retried rather than published short.
* Fixed: regional language codes (e.g. Traditional Chinese zh-TW, Brazilian Portuguese pt-BR) now use the correct length instruction for their base language instead of falling back to English.
* Internal: added raw AI-response logging (length and head/tail preview, with secrets scrubbed) to make parsing issues diagnosable, and re-synced the translation catalogs (.pot/.po/.mo) with the new strings.

= 1.0.5 =
* Fixed: a manual "Quick Post" could repeatedly fail with a "busy running another post" message even when no other process was running. The internal concurrency lock acquired by the manual run was never released because the release ran in a try/finally block, and PHP does not execute finally blocks when a request ends via exit(). The lock is now released from a shutdown handler that always runs, so back-to-back manual posts work reliably.
* Fixed: several admin screen strings were always shown in English regardless of the site language - the RSS feed confirmation dialogs ("Purge history", "Delete this feed"), the model-test result label, an empty-response error message, the "HTTP ..." error prefix, two scheduling FAQ answers, and the similarity-check hint on the task form.
* Fixed: the translation catalogs (.pot/.po/.mo) had drifted out of sync with the source code, so a few already-translated strings fell back to English at runtime. The catalogs are regenerated and fully re-synced, and stale orphaned entries were removed.
* Internal: routed the remaining hardcoded JavaScript messages through the existing i18n mechanism, wrapped previously untranslatable PHP error/notice strings in translation functions, and corrected a plural-form inconsistency in the Japanese catalog.

= 1.0.3 =
* Internal: refactored admin CSS structure. The single `admin.css` (and the modern theme overlay `admin-modern.css`) have been split by responsibility into 5 files under `assets/css/`: `admin-tokens.css`, `admin-base.css`, `admin-components.css`, `admin-pages.css`, and `admin-responsive.css`. No visual change is expected.
* Internal: reduced `!important` declarations from 141 to 1 by resolving selector specificity (e.g. scoping the generated-posts table under `.aiap-logs-table-section table.wp-list-table.aiap-generated-posts`) and removing duplicate/dead selector blocks. The remaining `!important` is on the mobile `html, body { overflow-x: hidden }` guard, which is required because `html`/`body` selectors are lower specificity than `body.wp-admin` from WP core.
* Internal: removed all inline `style` attributes and inline event handlers from PHP templates. Static styles are now expressed as CSS classes (e.g. `.aiap-doc-updated-at`, `.aiap-hidden`), and event handlers are bound from `admin.js` via class selectors.

= 1.0.2 =
* Similarity detection: expanded comparison scope from the past 7 days to all-time (most recent 20 posts).
* Pre-generation duplicate-topic prompt: increased from 10 to 20 most recent titles.
* AI similarity judgment: increased per-past-post excerpt from 160 to 300 characters (sent up to 10 posts).
* Regeneration prompt: increased the closest-match excerpt from 240 to 300 characters.

= 1.0.0 =
* Initial release.
* Text AI provider settings (Claude, OpenAI, Gemini, Mistral, Groq, DeepSeek, OpenRouter).
* Image provider settings (DALL-E, Imagen, Stability, Flux/Fal.ai, Unsplash, Pexels, Pixabay, Openverse).
* Per-task scheduling with day-of-week and time slots.
* Missed schedule recovery preserving the original publish time.
* Similarity detection with keyword and optional AI scoring.
* Configurable retry control (1 to 10 attempts).
* 7-day local execution logs.
* Encrypted API key storage (AES-256-CBC).
* SEO output: meta description, focus keyword, JSON-LD schema, OGP, canonical URL, internal linking, related posts, reading time.
* Optional integration with Yoast SEO, Rank Math, and All in One SEO.
* English and Japanese localization. Article generation supports approximately 50 languages.

== Upgrade Notice ==

= 1.0.5 =
Fixes a manual Quick Post that frequently reported "busy running another post"; also includes localization fixes for admin strings.

= 1.0.3 =
Internal CSS refactor only. No visual change expected.

= 1.0.2 =
Improves similarity detection by comparing against all past posts (most recent 20) instead of the past 7 days.

= 1.0.0 =
Initial release.
