We built DEV3 AI Review Summarizer & Sentiment Analyzer as a WooCommerce plugin in PHP, with a React admin and a server-rendered storefront widget, using the Google Gemini API through a shared core used across DEV3's plugins.
Key design decisions
- Reviews are data, never instructions. Reviews are sent as a JSON array inside a
<reviews> fence, encoded with JSON_HEX_TAG so no review can close the fence. The system instruction tells the model to ignore instructions inside it and to list such reviews in a flagged array.
- Personal data stays on the site. Only review text, star rating, month and the verified-owner flag are sent. Reviewer names, emails and IPs never leave WordPress, and emails, phone numbers and links inside review text are redacted first.
- Structured output with hard limits. The response schema gives every free-text string a
maxLength, enums for fit and keyword sentiment, and ranges for scores and shares. A PHP parser re-sanitises the answer anyway: tags and links stripped, sentiment rescaled to exactly 100 with largest-remainder rounding, out-of-range flags dropped.
- Fingerprint, don't poll. A hash of review IDs, text hashes and ratings, plus language, locale and prompt version, is stored with each summary. An unchanged review set is skipped without an API call.
- Debounced background work. New, approved, edited or deleted reviews queue one Action Scheduler job per product (with a WP-Cron fallback); a nightly sweep refreshes only stale and missing summaries, spaced 20 seconds apart.
- Moderator locks. Staff can edit any field and save and lock. Locked summaries are never regenerated automatically, and the admin shows which reviews the AI flagged.
Architecture
Summaries live in product meta with their fingerprint, model, token count and flagged review IDs. The storefront widget is server-rendered and escaped, can be placed above the reviews, below Add to cart, in its own tab, through a shortcode or a dynamic block, and loads about 6 KB of CSS and no JavaScript. It renders nothing when a product has no summary and never prints schema.org ratings. The admin Products screen shows fresh, stale, locked and missing summaries, with bulk generate and a live progress bar.