fix: attach images immediately + upgrade image prompts to v2

Two fixes:

1. Image attachment: moved set_post_thumbnail() and Image B post meta
   into generate_and_attach_images() so they persist immediately after
   each image generates. Previously the caller set them after both images
   completed — if the process timed out (common with GPT-5 Image at
   ~30s/image), the featured image was never attached and Image B was
   never attempted.

2. Image prompts: replaced FLUX.1-optimized rewriter system prompt and
   90s infomercial style suffix with prompts optimized for Gemini Flash
   Image and GPT-5 Image. New style: premium scientific lifestyle
   photography with golds/teals color grading. Includes one-time migration
   to update stored style suffix.

Also logs when Image B is skipped due to missing source data (previously
silent), helping diagnose why some posts only get one image.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-18 12:17:05 +07:00
parent dd406c5ba6
commit 1a2af595c6
6 changed files with 63 additions and 41 deletions

View File

@@ -138,24 +138,12 @@ class PRAutoBlogger_Post_Assembler {
$source_data = ( new PRAutoBlogger_Source_Collector() )->get_source_data_for_image( $idea->get_source_ids() );
try {
// The pipeline now sets featured image and Image B meta
// internally, immediately after each image generates. This
// ensures attachment persists even if the process times out
// before this method returns.
$result = ( new PRAutoBlogger_Image_Pipeline() )->generate_and_attach_images( $post_id, $post_data, $source_data );
if ( isset( $result['image_a_id'] ) ) {
set_post_thumbnail( $post_id, $result['image_a_id'] );
PRAutoBlogger_Logger::instance()->info(
sprintf( 'Set featured image (attachment %d) for post %d', $result['image_a_id'], $post_id ),
'publisher'
);
}
if ( isset( $result['image_b_id'] ) ) {
update_post_meta( $post_id, '_prautoblogger_image_b_id', $result['image_b_id'] );
PRAutoBlogger_Logger::instance()->info(
sprintf( 'Stored Image B (attachment %d) for post %d', $result['image_b_id'], $post_id ),
'publisher'
);
}
if ( ! empty( $result['errors'] ) ) {
foreach ( $result['errors'] as $error ) {
PRAutoBlogger_Logger::instance()->warning( 'Image warning for post ' . $post_id . ': ' . $error, 'publisher' );