# comment-draft-replies: held reply drafts for moderators

[comment-draft-replies](https://github.com/IndianOpinion/comment-draft-replies) is a WordPress plugin that drafts a reply to each eligible reader comment with a language model and holds it beside the comment for a moderator. It is for sites where editors have little time to answer readers. Licence MIT. Version v0.1.0, released 18 November 2026.

It was written from scratch from an idea, as one of the utilities described on the [engineering blog](https://indianopinion.org/blog/). It has not run on a live site, and its PRD says "measured result: none yet".

## The problem

Some comments deserve an answer: a question about a fact, a correction, a fair challenge. Editors rarely have time to write those answers, so readers wait and then stop asking. Sites that hold every comment for moderation make it worse, because a comment can sit unseen for days.

A model can write a first draft in seconds. It cannot be allowed to publish. It can be wrong, it can be baited by a hostile comment, it can be told what to say by text hidden in a comment, and it speaks in the site's name. What was missing was a tool that drafts the reply, puts it in front of an editor beside the comment, and publishes nothing until a person clicks.

## What it does

- Decides by rules, with no network call, whether a new comment is worth a draft, and records every failing rule on the comment.

- Queues a draft, calls the model once, validates the answer, and stores it as ready, declined or failed.

- Shows the draft below the comment on the Comments screen and on a Reply drafts screen.

- Lets a moderator publish as written, edit and publish, regenerate with a note, or discard. For a held comment there is one button, "Approve comment and publish reply".

- Offers WP-CLI commands for status, listing, running, backfill, a kill switch, the cap and clearing a provider hold.

## How it works

On comment_post, Intake runs inside a catch-all so a reader's comment is never affected. It makes three database reads and no HTTP call. An eligible comment gets one INSERT IGNORE row, and a unique key on the comment id makes a repeated hook call a no-op. A skip writes one comment meta entry with reason codes, so a moderator can see why a comment got no draft.

The intake rules cover comment type (the empty type and comment are treated alike), spam and trash state, staff, the plugin's own replies, post state, length bounds, links, contact details, blocked words, the author's history, rate limits and the daily cap. A filter, cdreplies_should_draft, can veto but never force.

Runner works from WP-Cron, WP-CLI or an optional gen-queue job. It claims a draft with a conditional update that stores a random token, re-checks the comment and post, reads the switch and any hold fresh, takes a cap slot, makes one call, and validates. Drafts live in their own table, not the comments table, so they cannot reach comment queries, feeds, counts or page caches.

The model sees the site name and language, optional voice notes, the post title and excerpt, up to three earlier comments in the thread and the comment. It sees the commenter's name only if you allow it. It never sees email, IP address, user agent, website or user id. Reader text sits inside marked data blocks the prompt says not to obey.

Publishing goes through Review\Publisher, the only place a reply is created, and then through core's wp_new_comment(). Core sends the notifications it sends for any hand-written reply. A typical setup:

define('CDREPLIES_PROVIDER_KEY', 'your-key');
define('CDREPLIES_DISABLED', true); // stops everything at once

## Guard rails

- There is no setting, constant, filter, cron event, CLI command or REST route that publishes on its own. A test walks every one of them.

- Publishing needs the REST route, a logged-in cookie session for the same user, the REST nonce and the plugin's own nonce, plus the moderate_comments and edit_post capabilities. Application passwords get a 401.

- One conditional update decides the winner when two moderators click at once.

- The kill switch is read fresh before every call. CDREPLIES_DISABLED forces it on.

- The daily cap defaults to 30 calls, counted atomically, retries and regenerations included. Per thread, post and author limits default to 2 per 24 hours, 6 per hour and 3 per 24 hours.

- An authentication or credit error starts a one-hour hold. Timeouts, 429 and 5xx back off at 1, 5 and 15 minutes.

- A reply must not be empty, over length, link to a host outside an allow list (your own host by default), contain an email or phone number, contain invisible or control characters or prompt markers, or copy the comment. One retry, then failed.

- The plugin writes only its own rows, its own meta and a reply a person asked for. It never deletes, trashes or spams a comment, and it logs ids and reason codes, never comment text.

## What review changed

An independent review of the build PR fixed these before the merge.

- Model text was published as markup. The validator decodes entities, so an escaped script tag became a real one in the stored reply, and an administrator publishing it skipped kses. The model's text is now encoded on publish.

- The publish route now also requires core's cookie authentication of the REST request, on top of refusing application passwords.

- The commenter name sat outside the data block in the prompt. It is now inside, and reader text loses hidden and direction-control characters and has every double bracket broken, so a comment cannot close a data block early.

- Rate limits had a race. Two concurrent comments in one thread could both pass. Count and insert now run under a per-site MySQL named lock that waits at most two seconds and never blocks the reader.

The review also fixed the script check, which wrongly flagged a Hindi reply to a Hindi comment containing English words, and corrected the three optional integrations to match the released contracts of their sibling plugins.

## Limits and what is next

- Comments inserted with wp_insert_comment() directly, such as imports, do not fire comment_post and get no draft. Use the backfill command on purpose.

- Limits and the cap count drafts and calls, not money. Use spend-meter if you need a cost ceiling.

- The script check uses Unicode properties. It is a hint, not a language detector.

- Drafts are kept for 90 days after they end.

No issues are open on the repo. Test status: this is v0.1.0. There are 149 PHPUnit tests with 958 assertions pass on PHP 8.3 against a throwaway MySQL 8.0, with PHPStan level 8 and phpcs clean. The model calls are tested against stubs and a mock transport, and the plugin has not run on a live site. The CI workflow has not run on GitHub, and there is no production mileage.

## Install

It needs PHP 8.1 or later and WordPress 6.4 or later. Without Composer you can supply your own caller through the cdreplies_model_caller filter, and an example is in the repo.

cd wp-content/plugins
git clone https://github.com/IndianOpinion/comment-draft-replies.git
cd comment-draft-replies
composer install --no-dev

[All 47 utilities](https://indianopinion.org/blog/open-source/) · [comment-draft-replies on GitHub](https://github.com/IndianOpinion/comment-draft-replies)

Canonical: https://indianopinion.org/blog/open-source/comment-draft-replies/

AI disclosure: Every summary and comment here is written by AI and published automatically, without a person reviewing each article. We do no original reporting. How this works: https://indianopinion.org/ai-use-policy/
