Skip to content

Add bulk "Generate AI Summary" action to the posts list table#650

Draft
prasadkarmalkar wants to merge 3 commits into
WordPress:developfrom
prasadkarmalkar:feat/bulk-posts-summary
Draft

Add bulk "Generate AI Summary" action to the posts list table#650
prasadkarmalkar wants to merge 3 commits into
WordPress:developfrom
prasadkarmalkar:feat/bulk-posts-summary

Conversation

@prasadkarmalkar

@prasadkarmalkar prasadkarmalkar commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #614

Why?

AI summary generation is only available from within the block editor for a single post at a time. This PR adds a bulk workflow that lets users generate summaries for multiple posts in a single action directly from the list table.

How?

References from the existing Alt Text Generation bulk action pattern:

  1. PHP (three new methods on Summarization experiment):

    • register_bulk_action() — appends "Generate AI Summary" to the bulk actions menu.
    • handle_bulk_action() — validates capabilities (edit_posts + per-post edit_post), then redirects back to edit.php with wpai_bulk_summary=1&wpai_post_ids=1,2,3 query args.
    • maybe_enqueue_bulk_assets() — detects the redirect on page reload, sanitizes post IDs, resolves the correct REST base from the current post type (so pages and custom post types work), and enqueues the bulk script with localized data (window.aiSummarizationBulkData).
  2. JavaScript (src/experiments/summarization/bulk.ts, new file):

    • On DOMContentLoaded, reads window.aiSummarizationBulkData and processes posts sequentially.
    • Checks provider availability; shows an admin notice error if no AI connector is configured.
    • For each post: calls runAbility('ai/summarization', { context: postId }) (the ability fetches post content from the DB itself), fetches raw block content via the REST API, strips any pre-existing summary block, prepends the new one, and saves both content and meta.ai_generated_summary in a single apiFetch POST.
    • Displays a live-updating progress notice and a final success/failure summary.
    • Cleans up wpai_bulk_summary and wpai_post_ids from the URL via history.replaceState.
  3. Webpack (webpack.config.js): Adds experiments/summarization-bulk entry pointing to bulk.ts.

Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): Claude Sonnet 4.6
Used for: Initial code skeleton. Final implementation reviewed and edited by me.

Testing Instructions

Prerequisites: An AI connector must be configured in Settings → Connectors.

  1. Go to Posts → All Posts (or Pages → All Pages).
  2. Select two or more posts using the checkboxes.
  3. Open the Bulk Actions dropdown — confirm "Generate AI Summary" is listed.
  4. Select "Generate AI Summary" and click Apply.
  5. The page reloads; a progress notice appears: "Generating summaries: 0 / N…"
  6. Wait for processing to complete — the notice updates to show success/failure counts.
  7. Open one of the processed posts in the block editor and confirm:
    • An AI Summary block group is prepended to the content.
    • The post meta ai_generated_summary is added
  8. Run the bulk action again on the same posts — confirm the old summary block is replaced, not duplicated.
  9. Repeat on the Pages list table to confirm post-type handling works.
  10. Negative test: Disable the summarization experiment in Settings → AI and confirm the bulk action is no longer listed.

Screenshots or screencast

Screen.Recording.2026-06-03.at.10.28.13.AM.mov

Changelog Entry

Added - Bulk "Generate AI Summary" action to the posts and pages list table, enabling AI summary generation for multiple posts at once without opening the block editor.

Open WordPress Playground Preview

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.11111% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.19%. Comparing base (64e8032) to head (cd8e3d7).

Files with missing lines Patch % Lines
...cludes/Experiments/Summarization/Summarization.php 11.11% 40 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #650      +/-   ##
=============================================
- Coverage      74.57%   74.19%   -0.38%     
- Complexity      1754     1770      +16     
=============================================
  Files             85       85              
  Lines           7548     7593      +45     
=============================================
+ Hits            5629     5634       +5     
- Misses          1919     1959      +40     
Flag Coverage Δ
unit 74.19% <11.11%> (-0.38%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for bulk summary generation

1 participant