Why
Currently datamachine/generate-image only sets the generated image as a featured image. If a post already has a featured image, the new image lands in the media library unattached. There's no way to add images into post content via the ability.
Proposal
Add a mode parameter to control post-sideload behavior:
Modes
featured (default, current behavior) — Set as featured image. Skip if post already has one.
insert — Sideload AND insert a <!-- wp:image --> block into post_content.
Placement Algorithm (position parameter)
after_intro (default for insert) — After the first paragraph block
before_heading — Before the next H2/H3 heading
evenly — Distribute evenly through content (for multiple images, insert at equal intervals between blocks)
end — Append at the bottom of post content
index:N — Insert before block at index N (0-based)
Interface
// Single image insert
wp_get_ability('datamachine/generate-image')->execute([
'prompt' => 'A colorful parrot in a rainforest',
'post_id' => 1234,
'mode' => 'insert',
'position' => 'after_intro',
]);
// Featured image (default, existing behavior)
wp_get_ability('datamachine/generate-image')->execute([
'prompt' => 'A colorful parrot in a rainforest',
'post_id' => 1234,
// mode defaults to 'featured'
]);
Implementation scope
ImageGenerationAbilities.php — Add mode and position to input schema, pass through to context
ImageGenerationTask.php — Add insertImageInContent() method alongside existing trySetFeaturedImage():
- Parse
post_content into Gutenberg blocks (parse_blocks())
- Find insertion point based on
position algorithm
- Build
<!-- wp:image --> block with attachment data, alt text, proper alignment
- Serialize blocks back and
wp_update_post()
- Route by mode — After sideload:
featured → trySetFeaturedImage(), insert → insertImageInContent()
Block format
<!-- wp:image {"id":123,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="URL" alt="ALT" class="wp-image-123"/></figure>
<!-- /wp:image -->
Builds on #229/#234 (standalone post_id support).
Why
Currently
datamachine/generate-imageonly sets the generated image as a featured image. If a post already has a featured image, the new image lands in the media library unattached. There's no way to add images into post content via the ability.Proposal
Add a
modeparameter to control post-sideload behavior:Modes
featured(default, current behavior) — Set as featured image. Skip if post already has one.insert— Sideload AND insert a<!-- wp:image -->block intopost_content.Placement Algorithm (
positionparameter)after_intro(default for insert) — After the first paragraph blockbefore_heading— Before the next H2/H3 headingevenly— Distribute evenly through content (for multiple images, insert at equal intervals between blocks)end— Append at the bottom of post contentindex:N— Insert before block at index N (0-based)Interface
Implementation scope
ImageGenerationAbilities.php— Addmodeandpositionto input schema, pass through to contextImageGenerationTask.php— AddinsertImageInContent()method alongside existingtrySetFeaturedImage():post_contentinto Gutenberg blocks (parse_blocks())positionalgorithm<!-- wp:image -->block with attachment data, alt text, proper alignmentwp_update_post()featured→trySetFeaturedImage(),insert→insertImageInContent()Block format
Builds on #229/#234 (standalone post_id support).