=== CRAI Content Updater ===
Contributors: mark456321
Tags: ai, content-refresh, seo-optimization, evergreen-content, content-optimization
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 2.5.5
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI-powered content refresh tool. Keep your WordPress posts accurate and ranking with Claude, OpenAI, or Gemini. Unlimited refreshes — free, forever.

== Description ==

**CRAI Content Updater keeps your WordPress content accurate, competitive, and ranking.**

Over time, blog posts go stale: prices change, statistics become outdated, year references age, and SEO meta loses relevance. CRAI Content Updater uses the AI provider of your choice to research current facts and refresh outdated content — saving every change as a draft for your review before anything goes live.

**Your original content never changes without your approval.**

= How It Works =

1. Pick any published post or page from the Refresh Content tab
2. Choose what to update: facts, dates, prices, reviews, SEO metadata, or tone
3. The AI reads, diagnoses, and refreshes your content, saving it as a draft
4. Review the changes, approve, and the live post updates — or discard it

= Key Features =

* **Unlimited Content Refreshes** — Refresh as many posts as you want, as often as you want. No caps, no monthly limits, no license keys.
* **Draft Review Workflow** — Every update saves as a draft. Your live post never changes until you explicitly approve it.
* **Multi-Provider Support** — Works with Claude (Anthropic), OpenAI (GPT-4.1), Gemini Paid, and Gemini Free. Bring your own API key.
* **Gemini Free Built-In** — Works out of the box with a free Google Gemini API key. No credit card required to get started.
* **Bulk Refresh** — Select multiple posts and refresh them sequentially in the background.
* **Freshness Scoring** — Posts sorted by staleness so you always know what needs attention first.
* **Elementor Support** — Widget-by-widget updates preserve your Elementor layout.
* **Yoast SEO & Rank Math Compatible** — Reads and writes focus keyword, SEO title, and meta description for both Yoast SEO and Rank Math. When the SEO update option is enabled, the AI rewrites your meta fields and saves them directly to the draft — no manual copy-paste required.
* **Update History** — Full log of every AI refresh with before/after word counts and change summaries.
* **Performance Analytics** — Track post-refresh view trends with built-in pageview tracking (no third-party services).
* **AI Provider Status Widget** — Live sidebar indicator shows which AI provider is active and whether your API key is working.
* **Before/After Compare Modal** — Side-by-side diff of every change the AI made before you approve.
* **Accurate Cost Tracking** — All API calls (including multi-stage Deep Research) are counted and displayed in history.

= What Can Be Refreshed =

* Dates and time references — "in 2022" -> "currently"
* Facts, statistics, and data — outdated figures updated with current values
* Prices and product information — pricing and feature lists kept current
* Review scores and ratings — star ratings, pros/cons, verdicts updated
* SEO title and meta description — rewritten with current year and keyword

= External Services =

This plugin connects to AI provider APIs to perform content analysis and rewriting. AI processing happens on the provider's servers — that is the core function of the plugin.

You choose which provider to use and supply your own API key. Supported providers:

* **Anthropic Claude** — [anthropic.com](https://www.anthropic.com/) · [Terms of Service](https://www.anthropic.com/legal/consumer-terms) · [Privacy Policy](https://www.anthropic.com/legal/privacy)
* **OpenAI** — [openai.com](https://openai.com/) · [Terms of Service](https://openai.com/policies/terms-of-use) · [Privacy Policy](https://openai.com/policies/privacy-policy)
* **Google Gemini** (paid and free tier) — [ai.google.dev](https://ai.google.dev/) · [Terms of Service](https://policies.google.com/terms) · [Privacy Policy](https://policies.google.com/privacy)

**What is sent:** When you trigger a refresh, the plugin sends the post title, post content, focus keyword (if available), and your selected update preferences to the AI provider you have configured. The provider's response is saved locally as a WordPress draft.

**What is NOT sent:** Nothing is sent to CRAI servers. API keys and post content stay between your site and the AI provider you select. The plugin does not phone home, collect telemetry, or transmit any data to third parties beyond your chosen AI provider.

API keys are stored in the WordPress options table on your own database.

= Pro Version =

A separate, paid Pro plugin is available at [contentrefreshai.com](https://contentrefreshai.com/). The Pro plugin is hosted independently — it is not part of, and not unlockable from, this free plugin. The free plugin's code is fully functional with no hidden or locked features.

= Requirements =

* An API key from your chosen AI provider (Google Gemini has a free tier — no credit card required)
* WordPress 5.8 or higher
* PHP 7.4 or higher

== Installation ==

= Automatic Installation =

1. Go to Plugins -> Add New
2. Search for "CRAI Content Updater"
3. Click Install Now then Activate

= Manual Installation =

1. Download the plugin zip
2. Go to Plugins -> Add New -> Upload Plugin
3. Upload and activate

= Setup =

After activation a setup wizard will guide you through choosing your AI provider and adding your API key. Google Gemini has a free tier — no credit card required.

== Screenshots ==

1. The main Refresh Content dashboard — see all your posts and pages sorted by staleness, with stale age, word count, and one-click Refresh or bulk update controls.
2. The Pending Drafts screen — review every AI-generated update before it goes live, with a full breakdown of what was changed across dates, facts, prices, SEO, and word count.
3. The History log — a full record of every refresh showing the AI provider, model, token usage, estimated cost in USD, word count changes, and number of edits made.
4. Settings page — choose your AI provider (Claude, OpenAI, Gemini), enter your API key, select a model, and configure exactly what gets updated on every refresh.
5. The per-article update options popup — choose what to refresh for a single article including Deep Research fact-checking, dates, facts, prices, reviews, SEO, and whether to bump the published date on approval.
6. The live update progress modal — real-time 3-step progress indicator showing Research, Rewrite, and Save Draft stages as the AI works through your article.
7. The before/after Compare view — a sentence-level diff showing exactly what the AI changed, with red for removed text and green for updated text, plus token count and estimated cost in the header.
8. A second example of the Compare view — showing fact updates like corrected subscriber counts and fixed typos, so you can approve only the changes you're happy with.

== Frequently Asked Questions ==

= Do I need my own AI API key? =

Yes. You supply your own API key from Anthropic, OpenAI, or Google. Google Gemini has a free tier that works well for most sites — no credit card required.

= Are there any usage limits inside the plugin? =

No. This plugin has no refresh limits, no license activation, no time trials, no quotas. Refresh as many posts as often as you want.

The only practical limits come from the AI provider you choose — for example, Google's free Gemini tier has lower request rates and a smaller output token cap than the paid Gemini API.

= Does it change my live posts automatically? =

Never. Every AI refresh saves as a private draft. Your live post only updates when you explicitly approve the draft.

= Is my content sent anywhere other than the AI provider? =

No. Your post content is sent only to the AI provider API you configure. Nothing is sent to CRAI servers or anywhere else.

= Does the plugin work with Yoast SEO or Rank Math? =

Yes — CRAI Content Updater has native support for both Yoast SEO and Rank Math. When you enable the "SEO title, meta & keywords" update option, the plugin reads your existing focus keyword, SEO title, and meta description from whichever plugin you have installed, sends them to the AI for improvement, and writes the updated values back to the correct meta fields on the draft. No manual copy-paste required. If neither plugin is active, the plugin falls back to the post title as the focus keyword.

= Does the plugin work with Elementor? =

Yes. The plugin detects Elementor posts and performs widget-by-widget updates to preserve your layout.

= Which AI providers are supported? =

Claude (Anthropic), GPT-4.1 (OpenAI), Gemini 2.5 Pro / 2.5 Flash / 1.5 Pro (Google paid), and Gemini 2.5 Flash Lite (Google free tier).

= How much does a refresh cost? =

It depends on your AI provider and article length. Rough estimates per refresh:
* Gemini Free — $0.00 (free tier)
* Gemini Paid / GPT-4.1 — $0.05–$0.20
* Claude Haiku — $0.05–$0.20
* Claude Sonnet — $1.00–$4.00 (high quality, longer articles)
* Claude Opus — $3.00–$8.00+ (highest quality, slowest)

The plugin displays token usage and estimated cost in the History tab after each refresh.

= Why is Claude so much more expensive? =

Claude Sonnet and Opus are significantly more expensive per token than GPT-4.1 or Gemini. For a long article with Deep Research enabled, Claude makes 3-5 separate API calls (research, fact-check, rewrite, SEO). Use Claude Haiku for routine updates and Sonnet/Opus for your most important content.

== Changelog ==

= 2.5.5 =
* Fixed all Plugin Check warnings in `uninstall.php`: renamed variables to use `crai_` prefix (`$crai_options`, `$crai_option`, `$crai_meta_keys`, `$crai_meta_key`, `$crai_table`) to satisfy the `PrefixAllGlobals` naming convention.
* Added `phpcs:ignore` comments for intentional direct DB queries in `uninstall.php` — deleting by `meta_key` and dropping the custom table are expected and correct at uninstall time.

= 2.5.4 =
* Added missing `uninstall.php` — removes all plugin options, post meta, the custom performance views table, and transients on uninstall. Required by WordPress.org plugin guidelines.
* Fixed misleading PRO badges on the Upgrade page: "Unlimited Refreshes", "Bulk Refresh Automation", and "Full History & CSV Export" are all fully functional in the free plugin and are now correctly labelled FREE.
* Fixed License & Plans pricing card: corrected the free tier feature list to accurately reflect unlimited refreshes, bulk refresh, and CSV export as included. Removed false "✗ Unlimited refreshes" and "1 article create/month" limit claims.
* Fixed Free vs Pro comparison table: "Full history & CSV export" and "Bulk refresh automation" now correctly show ✓ for the free tier.

= 2.5.3 =
* Fixed Plugin Check WARNING: `post__not_in` exclusionary query parameter removed from `get_posts()` call in `class-crai-updater.php`. Exclusion logic moved to PHP-side filtering to avoid the VIP performance sniff.
* Fixed Plugin Check WARNING: plugin tags reduced from 7 to the WordPress.org maximum of 5. Yoast and Rank Math compatibility remains documented in the description and FAQ.

= 2.5.2 =
* Updated "Tested up to" to WordPress 7.0.
* Fixed Plugin Check ERROR: "Tested up to" was below the current WordPress version, hiding the plugin from WordPress.org search results.
* Fixed Plugin Check WARNING (×2): interpolated `{$table}` variable inside `$wpdb->prepare()` calls in `class-crai-performance.php`. Replaced with `esc_sql()` concatenation — the correct WordPress pattern for dynamic table names.
* Fixed Plugin Check WARNING: `exclude` parameter in `get_posts()` replaced with `post__not_in` in `class-crai-updater.php`.

= 2.5.1 =
* Added estimated API cost (USD) to the Draft Created modal — displayed below the word count so you can see at a glance what each refresh cost. Includes an estimate disclaimer.
* Documented native Yoast SEO and Rank Math compatibility — the plugin reads and writes focus keyword, SEO title, and meta description for both plugins. Now reflected in the feature list, FAQ, and plugin tags.
* Updated readme.txt: added Yoast SEO and Rank Math to plugin tags, added compatibility bullet to Key Features, added new FAQ entry.

= 2.5.0 =
* Complete free-plugin release — zero Pro/trial/license gate code. No counters, caps, or license checks of any kind remain anywhere in the plugin.
* Removed all Pro-only PHP classes: AI image generation, internal links engine, Gutenberg block converter, SEO scorer, site-links scanner, brand voice system, and content creator module.
* Removed Freemius SDK entirely (vendor/ directory deleted).
* Rewrote CRAI_License class to 4 utility methods only — no gating logic whatsoever.
* Removed all Creator JavaScript blocks (V2JS, CRCJS, CRCJS2) that were still being output on every page load and causing silent JS errors that broke all button click handlers.
* Fixed critical JS bug: main jQuery(function($){...}) wrapper was missing its closing }); causing every button on every page (Refresh, Approve, Discard, Compare, Test Connection, Bulk Update) to silently fail.
* Fixed: $can_update undefined variable causing all Refresh buttons to render as disabled.
* Fixed: $img_api and $img_api_s undefined variables causing PHP warnings that disrupted page output.
* Fixed: orphaned PHP open tag (<?php with no code) on line 562 causing "unexpected token" parse error on activation.
* Fixed: orphaned deactivate-license JS block and orphaned else{ block left by earlier cleanup causing JS syntax errors.
* Added AI Provider Status Widget to the sidebar — shows active provider name, model, and Live/No Key status badge.
* Added per-model cost/speed warning in Settings below the Claude model selector.
* Fixed cost tracking in History: token accumulator was only counting the final rewrite API call. All API calls in the chain now accumulate tokens correctly.
* Removed Welcome screen (Step 1) from the setup wizard — first-time users now land directly on the Choose Plan screen.
* Expanded Upgrade to Pro page: replaced vague summary card with 12 individual feature cards.
* Fixed Performance Tracking listed as Pro-only in two places — it is a free feature.
* Sidebar redesigned: SVG icons for all nav items, gold star Upgrade nav item, green Free badge at bottom.
* readme.txt: updated Stable tag, description, FAQ, and full changelog.

= 2.4.23 =
* Fixed WordPress.org plugin tags — corrected to hyphenated format required by the plugin directory.

= 2.4.22 =
* Updated WordPress.org plugin tags to improve discoverability.

= 2.4.21 =
* Added max_uses cap on Claude web search tool calls to prevent runaway API costs on data-heavy articles.

= 2.4.20 =
* Fixed: Gemini 2.5 Flash/Pro grounding tool name corrected (camelCase).
* Fixed: rewrite_widgets_findreplace() missing prompt-build block causing blank prompts on Elementor posts.
* Fixed: Draft post slug now inherits the original post's slug correctly.

= 2.4.7 =
* Removed all remaining Pro/creator feature code remnants for WordPress.org Guideline 5 compliance.
* Fixed output escaping on additional unescaped echoes in the admin UI.
* Removed leftover dead variables from the old Freemius update-counting system.

= 2.4.6 =
* Removed Plugin URI from the main file header to resolve a WordPress.org submission error.

= 2.4.5 =
* Renamed plugin folder and text domain to match the approved WordPress.org slug.
* Set Author header and Contributors username. Replaced truncated LICENSE.txt with full GPL-2.0 text.

= 2.4.4 =
* Fixed: performance views table was never created on activation due to missing activation hook.
* Added lazy safety net (maybe_create_table) for users upgrading from earlier versions.

= 2.4.3 =
* Fixed: Performance baseline capture failing with MySQL syntax error after every draft approval.

= 2.4.2 =
* Fixed 6 output-escaping issues flagged by Plugin Check.

= 2.4.1 =
* Added dedicated "Upgrade to Pro" tab as a clearly-labeled advertisement for the separate paid Pro plugin.

= 2.4.0 =
* Removed all gated/locked Pro feature references. Comprehensive escaping pass. Large dead-code cleanup.

= 2.3.34 =
* WordPress.org free version — unlimited refreshes, no license required. Removed Freemius SDK.

== Upgrade Notice ==

= 2.5.5 =
Fixes all Plugin Check warnings in uninstall.php: variable naming (crai_ prefix) and phpcs ignores for expected direct DB queries. No functional changes.

= 2.5.4 =
Important compliance update: adds missing uninstall.php cleanup and corrects misleading Pro labels on features that are actually free (unlimited refreshes, bulk refresh, CSV export). Recommended for all users.

= 2.5.3 =
Fixes two Plugin Check warnings: removes exclusionary post__not_in query (logic moved to PHP filtering) and reduces plugin tags to the 5-tag WordPress.org limit.

= 2.5.2 =
Fixes all Plugin Check errors and warnings: updates "Tested up to" to WordPress 7.0, corrects two SQL interpolation warnings in the performance tracker, and fixes an exclusionary query parameter warning.

= 2.5.1 =
Adds estimated API cost display to the Draft Created modal. Documents built-in Yoast SEO and Rank Math compatibility. No breaking changes.

= 2.5.0 =
Major update: fixes all button click handler failures (Refresh, Approve, Discard, Compare, Bulk Update, Test Connection), adds accurate cost tracking in History, adds AI provider status widget, and removes all Pro/license gate code. Recommended for all users.

= 2.4.23 =
Fixed plugin tags format for WordPress.org compliance. No functional changes.

= 2.4.20 =
Important bug fixes: corrects Gemini 2.5 grounding failures, fixes blank-prompt crash on Elementor posts, and prevents draft slugs from being overwritten. Recommended for all users.

= 2.4.4 =
Critical fix: performance views table is now created correctly on activation. Recommended for all users.

= 2.4.3 =
Critical fix: Performance baseline capture was failing with a MySQL syntax error after every draft approval. Recommended for all users.

= 2.4.0 =
Major compliance update: removed all gated/locked Pro feature references, comprehensive escaping pass, and large dead-code cleanup. Recommended for all users.
