The Content Summarization experiment adds AI-powered content summarization to the WordPress post editor. It provides a "Generate AI Summary" button in the post status panel that uses AI to create concise summaries of post content. The generated summary is inserted as a group variation block at the top of the post content. The experiment registers a WordPress Ability (ai/summarization) that can be used both through the admin UI and directly via REST API requests.
When enabled, the Content Summarization experiment adds a "Generate AI Summary" button to the post status panel in the WordPress post editor. Users can click this button to automatically generate a summary of the current post content. The generated summary is inserted as a group variation block at the top of the post content. The summary is also saved to post meta for programmatic access.
Key Features:
- One-click summary generation from post content
- Automatically creates a group variation block with the summary
- Summary block can be regenerated from block toolbar
- Summary is saved to post meta (
ai_generated_summary) - Works with any post type that supports the editor
The experiment consists of two main components:
- Experiment Class (
WordPress\AI\Experiments\Summarization\Summarization): Handles registration, asset enqueuing, UI integration, and post meta registration - Ability Class (
WordPress\AI\Abilities\Summarization\Summarization): Implements the core summarization logic via the WordPress Abilities API
The ability can be called directly via REST API, making it useful for automation, bulk processing, or custom integrations.
The ability accepts the following input parameters:
array(
'type' => 'object',
'properties' => array(
'content' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'description' => 'Content to summarize.',
),
'context' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'description' => 'Additional context to use when summarizing the content. Can be a string of additional context or a post ID (as string) that will be used to get context from that post. If no content is provided but a valid post ID is used, the content from that post will be used.',
),
'length' => array(
'type' => 'string',
'enum' => array( 'short', 'medium', 'long' ),
'default' => 'medium',
'description' => 'The length of the summary.',
),
),
)The ability returns a plain text string:
array(
'type' => 'string',
'description' => 'The summary of the content.',
)The length parameter controls the target length of the generated summary:
short: 1 sentence; ≤ 25 wordsmedium(default): 2-3 sentences; 25-80 wordslong: 4-6 sentences; 80-160 words
The system instruction is dynamically adjusted based on the selected length.
The ability checks permissions based on the input:
-
If
contextis a post ID:- Verifies the post exists
- Checks
current_user_can( 'edit_post', $post_id ) - Ensures the post type has
show_in_restenabled
-
If
contextis not a post ID:- Checks
current_user_can( 'edit_posts' )
- Checks
The summarization ability can be called directly via REST API, making it useful for automation, bulk processing, or custom integrations.
POST /wp-json/wp-abilities/v1/abilities/ai/summarization/run
You can authenticate using either:
- Application Password (Recommended)
- Cookie Authentication with Nonce
See TESTING_REST_API.md for detailed authentication instructions.
curl -X POST "https://yoursite.com/wp-json/wp-abilities/v1/abilities/ai/summarization/run" \
-u "username:application-password" \
-H "Content-Type: application/json" \
-d '{
"input": {
"content": "This is a comprehensive article about artificial intelligence and machine learning. AI has revolutionized many industries including healthcare, finance, and transportation. Machine learning algorithms can now process vast amounts of data to identify patterns and make predictions that were previously impossible. The future of AI looks promising with advances in natural language processing, computer vision, and autonomous systems. These technologies are transforming how we work, communicate, and solve complex problems.",
"length": "medium"
}
}'Response:
"Artificial intelligence and machine learning are transforming industries like healthcare, finance, and transportation by enabling algorithms to process large datasets and make predictions. Advances in natural language processing, computer vision, and autonomous systems are reshaping how we work and solve problems."curl -X POST "https://yoursite.com/wp-json/wp-abilities/v1/abilities/ai/summarization/run" \
-u "username:application-password" \
-H "Content-Type: application/json" \
-d '{
"input": {
"context": "123"
}
}'This will automatically fetch the content from post ID 123 and generate a medium-length summary (default).
curl -X POST "https://yoursite.com/wp-json/wp-abilities/v1/abilities/ai/summarization/run" \
-u "username:application-password" \
-H "Content-Type: application/json" \
-d '{
"input": {
"content": "Your long article content here...",
"length": "short"
}
}'curl -X POST "https://yoursite.com/wp-json/wp-abilities/v1/abilities/ai/summarization/run" \
-u "username:application-password" \
-H "Content-Type: application/json" \
-d '{
"input": {
"content": "Your article content here...",
"context": "Focus on technical details and implementation",
"length": "long"
}
}'async function generateSummary(content, postId = null, length = 'medium') {
const input = { content, length };
if (postId) {
input.context = String(postId);
}
const response = await fetch(
'/wp-json/wp-abilities/v1/abilities/ai/summarization/run',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': wpApiSettings.nonce, // If using cookie auth
},
credentials: 'include', // Include cookies for authentication
body: JSON.stringify({ input }),
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.message || 'Failed to generate summary');
}
return await response.text(); // Returns plain text string
}
// Usage
generateSummary('Your article content here...', null, 'short')
.then(summary => console.log('Generated summary:', summary))
.catch(error => console.error('Error:', error));import apiFetch from '@wordpress/api-fetch';
async function generateSummary(content, postId = null, length = 'medium') {
const input = { content, length };
if (postId) {
input.context = String(postId);
}
try {
const summary = await apiFetch({
path: '/wp-abilities/v1/abilities/ai/summarization/run',
method: 'POST',
data: { input },
});
return summary; // Plain text string
} catch (error) {
console.error('Error generating summary:', error);
throw error;
}
}The ability may return the following error codes:
post_not_found: The provided post ID does not existcontent_not_provided: No content was provided and no valid post ID was foundno_results: The AI client did not return any resultsinsufficient_capabilities: The current user does not have permission to summarize content
Example error response:
{
"code": "content_not_provided",
"message": "Content is required to generate a summary.",
"data": {
"status": 400
}
}-
Enable the experiment:
- Go to
Settings → AI - Toggle Content Summarization to enabled
- Ensure you have valid AI credentials configured
- Go to
-
Test in the editor:
- Create or edit a post with content
- Scroll to the post status panel (right sidebar)
- Click the "Generate AI Summary" button
- Verify a paragraph block is created at the top with the summary
- Verify the summary is saved to post meta
- Click "Regenerate AI Summary" to test regeneration
- Select the summary block and use the toolbar button to regenerate
-
Test with different post types:
- The experiment loads for all post types that use the block editor
- Test with posts, pages, and custom post types
-
Test REST API:
- Use curl or Postman to test the REST endpoint
- Verify authentication works
- Test with different input combinations (content, context, length)
- Verify error handling for invalid inputs
- The experiment requires valid AI credentials to be configured
- The experiment works with any post type that uses the block editor
- Users must have
edit_postscapability (orread_postfor specific posts when using post ID context)
- Summary generation is an AI operation and may take several seconds
- The UI shows a loading state while generation is in progress
- Content is normalized before being sent to the AI (HTML stripped, shortcodes removed, etc.)
- The
normalize_content()function handles this processing - Additional context from post metadata (title, categories, tags) can be included when using post ID
- The ability uses
get_preferred_models()to determine which AI models to use - Models are tried in order until one succeeds
- Temperature is set to 0.9 for more creative and varied summaries
The system instruction guides the AI to:
- Generate concise, factual, and neutral summaries
- Use complete sentences, avoid persuasive or stylistic language
- Not use humor or exaggeration
- Not introduce information not present in the source
- Avoid generic introductions like "This article is about..."
- Target specific word counts based on the length parameter
- Use plain text only (no markdown or formatting)
- The summary is inserted as a
core/groupblock variation with a custom attribute (aiGeneratedSummary) - The block has a special class name (
ai-summarization-summary) for styling - Block controls allow regenerating the summary from the toolbar
- The summary is stored in post meta as
ai_generated_summary - This meta is registered for the
postpost type and is available in REST API - The meta is updated each time a summary is generated
- The meta can be accessed programmatically for custom use cases
- Summaries are generated in real-time and not cached
- The ability does not support batch processing (one summary per request)
- Generated summaries are suggestions and should be reviewed before publishing
- The summary block replaces any existing summary block when regenerated
- Summary length is approximate; actual length may vary slightly