=== Pewit AI Media Toolkit ===
Contributors: michalczajka, pewitlabs
Tags: media, alt text, seo, accessibility, openai
Requires at least: 6.1
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.3.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI-powered image metadata (ALT, title, caption, description), SEO filenames, smart scanning and safe bulk media management with backups.

== Description ==

AI Media Toolkit scans your media library, generates and completes image metadata (ALT, title, caption, description) with OpenAI, renames files to SEO-friendly names while keeping the same attachment ID, and protects you with backups and one-click rollback before any destructive operation.

= Fully functional and free =
Every feature in this plugin is free and fully functional: bring your own API key (OpenAI, Anthropic Claude or Google Gemini), scan your whole media library, generate or complete metadata one at a time or in the background for the entire library, bulk SEO filename rename, automatic backups, rollback & recovery, duplicate/quality analysis, client audit export, email reports, Media Library bulk actions and white-label branding. Nothing is locked behind a license.

Optionally, you can subscribe to **managed AI credits** (so you don't need your own API key) and priority support at https://pewitlabs.com/pricing/ — this is a paid external service, not a requirement to use the plugin.

= AI metadata generation =
* Generate ALT, title, caption and description from the image itself (vision model).
* Complete only the missing fields when some metadata already exists.
* Generation modes: Balanced, SEO, WCAG (accessibility-first).
* Multilingual: auto-detects language via WPML / Polylang / site locale, or forces a global language.
* Global website context field to steer tone and domain vocabulary.
* Configurable OpenAI model (default gpt-4o-mini) and API key test button.

= Scanning & usage detection =
* Smart scan of the whole library or only used images.
* Usage detection modes: Strict, Balanced, Debug.
* Detects usage in post content, featured images, WooCommerce galleries, Bricks, EtchWP and ACF fields.
* Filters: missing ALT, incomplete metadata, bad filename, supported only, skipped.

= SEO filenames =
* Build SEO filenames from product/page/post usage context.
* Rename existing files keeping the same attachment ID (references via ID stay intact).
* Replace a media file in place (keep ID), optional thumbnail regeneration and WooCommerce cache clear.
* Bulk SEO rename: only bad filenames, or all listed images.

= Background queue =
* Processes jobs in the background via WP-Cron.
* Configurable batch size and delay between batches.
* Pause, resume, stop and clear running jobs, with a live activity log.

= Safety, backups & recovery =
* Auto-backup before file changes, rename, replace and recovery operations.
* Snapshots of image files, attachment metadata and WooCommerce relations.
* One-click rollback of the last operation, manual snapshots, ZIP export.
* Emergency repair for broken / too-small product images after a bad rename.

= Reports & notifications =
* Duplicate and quality analysis with a media health score.
* CSV report export.
* Email notification when a background job finishes (basic / detailed / full).

== Installation ==

1. Upload the plugin ZIP through Plugins -> Add New -> Upload Plugin, or extract it to wp-content/plugins/pewit-ai-media-toolkit/.
2. Activate the plugin.
3. Open AI Media Toolkit -> Settings, paste your OpenAI API key, click Save & Test.
4. Run Scan images, then start generating metadata.

The plugin folder must always be pewit-ai-media-toolkit/ and the main file pewit-ai-media-toolkit.php.

== External services ==

This plugin connects to third-party services to generate image metadata. Please review this before use.

You choose the AI provider in the plugin settings and use your own API key (BYOK). No data is sent to any provider until you trigger a generation. Requests go directly from your site to the selected provider under your own key and that provider's terms. Nothing is sent to the plugin author.

OpenAI API (https://openai.com):
* What and when: when you generate image metadata (vision), generate an image (DALL·E), or run a text task, the image data/URL and/or text prompt are sent to OpenAI to produce ALT text, title, caption, description or image output.
* Data sent: the image data/URL, optional context text you configure, and the selected model name.
* Terms: https://openai.com/policies/terms-of-use — Privacy: https://openai.com/policies/privacy-policy

Anthropic (Claude) API (https://www.anthropic.com):
* What and when: only if you select Claude as the text provider — when you run a text generation task, your text prompt (and image data, for vision-capable models) is sent to Anthropic to produce the requested text.
* Data sent: the text prompt, optional context text you configure, and the selected model name.
* Terms: https://www.anthropic.com/legal/consumer-terms — Privacy: https://www.anthropic.com/legal/privacy

Google Gemini API (https://ai.google.dev):
* What and when: only if you select Gemini as the text provider — when you run a text generation task, your text prompt (and image data, for vision-capable models) is sent to Google's Generative Language API to produce the requested text.
* Data sent: the text prompt, optional context text you configure, and the selected model name.
* Terms: https://ai.google.dev/gemini-api/terms — Privacy: https://policies.google.com/privacy

Freemius (licensing & checkout — https://freemius.com):
* What and when: used for license activation, updates and (for paid plans) checkout as Merchant of Record. Opt-in is optional.
* Terms: https://freemius.com/terms/ — Privacy: https://freemius.com/privacy/

== Source code ==

All JavaScript and CSS shipped in this plugin (in assets/js and assets/css) is the original, hand-written, human-readable source. Nothing is minified, compiled, transpiled or generated by a build tool, so no separate source files are required — what you read in the plugin is the source. The only bundled third-party library is the Freemius SDK (vendor/freemius), whose source is available at https://github.com/Freemius/wordpress-sdk

== Frequently Asked Questions ==

= Do I need an OpenAI API key? =
Yes. The plugin uses your own OpenAI API key with access to a vision-capable model. Managed AI credit packs (no key required) are planned.

**How to get a key (quick steps):**
1. Sign up at https://platform.openai.com/ (this is not the same as ChatGPT Plus).
2. Add a payment method under Settings -> Billing and set a monthly spend limit.
3. Go to https://platform.openai.com/api-keys -> Create new secret key -> copy the sk-... value immediately (shown only once).
4. In WordPress: AI Media Toolkit -> Settings -> paste the key -> Save & Test.

Default model gpt-4o-mini is inexpensive for image metadata (typically a fraction of a cent per image).

= Will renaming files break links to my images? =
Renames keep the same attachment ID, so references made via attachment ID (most page builders, WooCommerce, ACF) stay intact. Always test on staging first and keep auto-backup enabled.

= Is there a ZipArchive requirement? =
Only for ZIP backup export. The rest of the plugin works without it.

== Changelog ==

= 1.3.1 =
* Fixed: removed all license/plan gating of built-in features from the wordpress.org build — every shipped feature is unconditionally free and fully functional (no trialware).
* Changed: the white-label client audit (PDF-ready export) is no longer part of the free build; it is an optional add-on feature.
* Changed: white-label brand/logo settings save for everyone in the free build.
* Added: "Source code" section documenting that all JS/CSS is hand-written, unminified source.
* Fixed: prefixed remaining globals (AIMT_DeactivatePrompt, aimt_backup_root/aimt_backup_base_dir) to avoid collisions.

= 1.3.0 =
* Changed: renamed to "Pewit AI Media Toolkit" (new slug pewit-ai-media-toolkit) for a distinctive directory name.
* Changed: every feature is now free and fully functional — no license gating of built-in features. Optional paid managed AI credits and support remain available as an external service.
* Added: External services documentation for OpenAI, Anthropic (Claude) and Google Gemini, including terms/privacy links.
* Fixed: removed Google Fonts (no external font requests); admin uses a system font stack.
* Fixed: client audit is rendered on demand and streamed instead of writing an HTML file to uploads.
* Fixed: removed unnecessary direct load of wp-admin/includes/media.php.
* Security: recovery candidates and folders are now strictly constrained to the uploads directory (realpath-based) to prevent path traversal from tampered meta.
* Fixed: dropped a filesystem-incompatible vendor filename; build now excludes spaced and *.dc.html artifacts.

= 1.2.8 =
* Fixed: Plugin Check i18n errors (translators comment placement); silenced advisory warnings (set_time_limit, direct DB cleanup queries, WPML/suite integration hooks, validated upload input).

= 1.2.7 =
* Fixed: fatal error on load ("Call to undefined function aimt_can_automate()") that broke autopilot scheduling and upload hooks.

= 1.2.6 =
* Fixed: remaining Plugin Check errors (i18n translators, rename fallback, inline AJAX nonce verification).

= 1.2.5 =
* Fixed: WordPress Plugin Check — i18n translators comments, output escaping, filesystem helpers, WP 6.1 minimum for object cache API.

= 1.2.4 =
* Fixed: WordPress.org Plugin Check i18n compliance for shared LLM client.

= 1.2.3 =
* Added: Settings provider selector — OpenAI, Claude (Pro), Gemini (Pro). Vision metadata and DALL·E remain OpenAI-only.

= 1.2.2 =
* Added: Agency client audit export (PDF-ready) with health score and white-label logo support.
* Changed: Pro backups use shared folder uploads/pewit-labs-backups/ai-media-toolkit/.
* Changed: Dashboard callout when AI Content Assist is active.

= 1.2.1 =
* Added: Send test email and Run scheduled scan now in Scheduled autopilot settings.
* Fixed: Scheduled scan no longer requires a verified API key for scan and email notifications.

= 1.2.0 =
* Added: Auto metadata on upload (Pro) — background ALT/title/caption after new uploads.
* Added: Scheduled library scan with optional auto-fix queue and email reports (Pro).

= 1.0.3 =
* Review prompt after 14 days of use (rate / snooze / dismiss).

= 1.0.2 =
* New setting: choose WordPress image size sent to OpenAI for metadata (default Large ~1024 px).

= 1.0.1 =
* Fixed: backup ZIP export now downloads (registered authenticated download handler).
* Fixed: saving settings no longer clears a stored API key when the key field is left empty.
* Changed: API key shown masked in Settings (last 4 characters only); Change key / Cancel flow.
* Changed: admin tab layout polish (Context, Language, Reports, Images, Recovery, Settings).
* See CHANGELOG.md for full history.

= 1.0.0 =
* Stable release: change history restore UI, first-run onboarding, broken-size audit/filter, bulk thumbnail regen and selected repair.
* See CHANGELOG.md for full history.

= 1.0.0-alpha.7 =
* Pro: background job to generate featured images for published posts that are missing one (Settings -> Featured image AI).

= 1.0.0-alpha.6 =
* Auto-generate featured image on publish when the post has no featured image yet (Pro, optional checkbox in Settings).

= 1.0.0-alpha.5 =
* Featured image settings: style preset (photo, illustration, regional aesthetics) + custom style prompt field.

= 1.0.0-alpha.4 =
* Pro: generate a featured image from post title/content in the post editor and set it immediately.
* Settings for image model, size and optional metadata on the generated image.

= 1.0.0-alpha.3 =
* Native Media Library: generate all metadata or change filename directly on each image (sidebar panel + list quick actions).
* API key must be saved and tested before generation; otherwise users see a link to Settings.
* Settings: hover help icon next to the OpenAI API key field.

= 1.0.0-alpha.2 =
* Sidebar tabs now show one workspace section at a time (mockup-style), including automatic tab selection from the WordPress submenu.
* Images table: new **Change filename** button per row for single-file SEO rename (Pro).

= 1.0.0-alpha.1 =
* Major admin UI redesign: Geist typography, modern sidebar navigation, dashboard KPI cards, light activity log, and refreshed forms/tables/buttons.
* OpenAI API key setup guide in Settings for beginners.
* Backup progress indicator, automatic ZIP/CSV downloads, and security hardening from 0.9.9.x.

= 0.9.9.2 =
* Manual recovery snapshots now show live progress and run in batches (no more "is it working?" or timeouts on large libraries).
* Fixed: backup ZIP / CSV downloads now start automatically instead of relying on a new-tab link that some browsers blocked.
* Fixed: CSV reports could download as .txt in some browsers; the download now sends the correct file type.

= 0.9.9 =
* Security hardening: backup and report folders are now access-protected (no public listing or download).
* Backup ZIPs and CSV reports are served through an authenticated, nonce-checked download handler instead of a public URL.
* CSV exports escape values that could trigger spreadsheet formula injection.

= 0.9.8 =
* Added a "Your plan" panel in the admin (current plan badge, manage license/invoices and upgrade links).
* Agency white-label: replace the plugin name and logo in the admin menu, dashboard header and job emails.

= 0.9.7 =
* Free/Pro/Agency feature gating: single-image generation, library scan and basic CSV report stay free; background bulk generation, bulk SEO rename, backups/recovery, analysis and email reports are now Pro.
* Added upgrade prompts and a "Upgrade to Pro" banner for free users, plus server-side enforcement of Pro-only actions.

= 0.9.6.1 =
* First build packaged for Freemius deployment. No functional changes versus 0.9.6.

= 0.9.6 =
* Added Freemius licensing bootstrap and bundled the Freemius SDK.
* Moved uninstall logic to a Freemius after_uninstall handler (settings kept by default during beta).
* Hardened license helpers so the plugin runs safely without the SDK.

= 0.9.5 =
* Media library menu and SEO filename UX fixes.

== Upgrade Notice ==

= 0.9.6.1 =
First Freemius-packaged build. Recommended for licensing and auto-updates.
