Scope AI to comment spam + native-search assistant#298
Conversation
Narrow the AI Copilot to the one analysis that earns its keep — comment spam scoring — and make the assistant find content with WordPress's native keyword search instead of pre-analyzed summaries. - Remove the bulk /ai/reindex endpoint (orphaned, unbounded full sweep) - Remove post & taxonomy-term auto-analysis (jobs, save_post/term hooks, schema_content, messages_for_post/term) and their Stable hooks - Keep comment analysis only (feeds the comments-window spam score) - Rewrite search_posts/pages/comments[_by_post] to take a `query` and run WP_Query s= / get_comments search=; drop the _desktop_mode_ai_analysis meta dependency so all published content is findable - Migration v2 unschedules leftover analyze_post/analyze_term cron events - Docs/readme/version synced (0.10.0 -> 0.11.0) + migration note - Tests: native search, comment-only migration, comment spam score Breaking: removes the post/term analysis hooks (desktop_mode_ai_post_prompt, _term_prompt, _post_analyzed, _term_analyzed, _supported_post_types, _supported_taxonomies, _schema_content). See docs/migration-ai-comment-only.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
This is a prior step to integrate with WordPress AI providers shipped on 7.0 |
|
@claude how you feel about leaving here a review? :) |
|
Claude finished @AllTerrainDeveloper's task in 2m 40s —— View job Code Review — PR #298
Overall verdict: looks solid. The architectural simplification is well-motivated and executed cleanly. The core loop (remove bulk reindex → remove post/term analysis → switch to native WP search → migrate cron cruft) is a tight diff with no surprises. A few things worth fixing before merge, and a few observations. Bugs / correctness1. Stale file header docblock in The top-of-file docblock still reads: That's the old behaviour. The tools now return real titles + excerpts via 2.
Performance3. N+1 queries in For every comment in the batch a foreach ( $comments as $comment ) {
$parent_post = get_post( $comment->comment_post_ID );With batch size 10 that's up to 10 extra queries per tool call. Comments on the same parent post (common) pay the penalty multiple times since WP's object cache is not seeded. A single Code quality / minor4.
5. There is a dangling orphan doc comment immediately before /**
* Runs the agentic content-search loop.
* …
* @return array|WP_Error
*/
/**
* Returns a friendly progress message for a tool name…The first docblock belongs to SecurityNo new issues. Good handling throughout:
TestsThe three new test files are well-structured and cover the right things:
One gap worth adding: MigrationMigration v2 ( The migration doc itself is clear and the hook-removal table is the right level of detail for plugin authors. Summary: Three items worth addressing before merge — the stale header docblock (#1), clarifying or removing the dead post/term branches in the meta helpers (#2), and the misplaced |
… docblock - search.php: fix the file header docblock that still described the old meta-based behaviour (now: native WP search returning title + excerpt) - analysis.php: drop the dead 'post'/'term' branches in save_meta/get_meta; they're comment-only now, documented as such (param kept for signature stability, non-comment types are a no-op) - search.php: kill the N+1 in search_comments by priming parent-post caches once via _prime_post_caches() before the per-comment loop - search.php: re-attach the run_search() docblock to its function (it had been left stranded above progress_message()) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Why
Enabling the AI Copilot used to behave like a site-wide indexing obligation: it auto-analyzed every post, page, and taxonomy term on save (sending content to OpenAI), and the assistant could only find content that had already been analyzed. There was also an orphaned
POST /desktop-mode/v1/ai/reindexendpoint that swept all published posts/pages/comments in one unbounded pass (posts_per_page => -1, commentnumber => 0).This narrows AI to the one analysis that earns its keep — comment spam scoring (it feeds the comments-window spam score) — and makes the assistant find content the way WordPress already does: native keyword search.
What changed
1. Removed the bulk reindex endpoint
Deleted
includes/ai-copilot/reindex.php, itsrequire_onceinbootstrap.php, and the route row inincludes/rest/README.md.POST /ai/reindexnow 404s (it had no built-in caller).2. Removed post & taxonomy-term auto-analysis; kept comment
save_post/created_term/edited_termhooks, theanalyze_post/analyze_termjobs, andmessages_for_post/messages_for_term/schema_content.analyze_commentstill runs on comment insert/edit and stores thespam/harmfulverdict the comments-window score reads.3. Assistant search → native WordPress queries
search_posts/search_pages/search_comments/search_comments_by_postnow take aquerystring and runWP_Query s=/get_comments search=. The_desktop_mode_ai_analysismeta_querydependency is gone, so all published posts/pages and approved comments are findable — returning real titles + excerpts. System prompt + tool descriptions rewritten to match.4. Upgrade cleanup
Migration v2 (
includes/migrations.php) callswp_unschedule_hook()for the now-deaddesktop_mode_ai_analyze_post/_analyze_termcron events. Existing post/term meta is left in place (hidden, harmless).5. Docs + version
hooks-reference.md,javascript-reference.md,register-ai-provider.md,README.md,readme.txt(+ changelog) synced; newdocs/migration-ai-comment-only.mdindexed indocs/README.md. Version bumped 0.10.0 → 0.11.0.6. Tests
aiNativeSearch.php— content with no analysis meta is found via keyword search; keyword filters the result set; entity builder works without meta.aiCommentOnlyMigration.php— migration v2 unschedules post/term jobs, leaves the comment job alone.commentsAiSpamScore.php—spamfloors the score at 75,harmfuladds 20, no-meta is a no-op.Removes the post/term analysis hooks documented as Stable/Experimental:
desktop_mode_ai_post_prompt,desktop_mode_ai_term_prompt,desktop_mode_ai_post_analyzed,desktop_mode_ai_term_analyzed,desktop_mode_ai_supported_post_types,desktop_mode_ai_supported_taxonomies,desktop_mode_ai_supported_types,desktop_mode_ai_schema_content. The comment-side equivalents remain. Seedocs/migration-ai-comment-only.md.Testing
npm run build— cleannpm run typecheck— cleannpm run test:js— 1519 passedwp_update_plugins()reaching WordPress.org from the offline container), untouched by this changephp -lon every changed PHP file — clean🤖 Generated with Claude Code