Fix duplicate image, remove hardcoded model references
Three fixes in one: 1. Duplicate image: prepend_caption_to_post() was embedding the full image + caption as a <figure> block, but the theme already displays the featured image. Now only the caption text is prepended — no second copy of the image. 2. Hardcoded model names: removed all FLUX.1/FLUX.2 references from model-agnostic code (pipeline, prompt builder, sideloader, OpenRouter provider, interface, admin labels). The Cloudflare provider still references FLUX since it specifically wraps that model family. 3. Test alignment: OpenRouterImagePricingTest was asserting against removed models (flux-2-pro, seedream). Updated to match current COST_PER_IMAGE entries (Gemini Flash, GPT-5 Image). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -145,7 +145,7 @@ class PRAutoBlogger_Image_Media_Sideloader {
|
||||
gmdate( 'Y-m-d_H-i-s' )
|
||||
);
|
||||
|
||||
return $base . '.png'; // Default to PNG since FLUX.1 outputs PNG.
|
||||
return $base . '.png'; // Default to PNG — most image models output PNG.
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,12 +19,12 @@ class PRAutoBlogger_Image_Pipeline {
|
||||
/**
|
||||
* Default image dimensions (landscape).
|
||||
*/
|
||||
// FLUX.1 requires both dimensions to be divisible by 8.
|
||||
// Dimensions must be divisible by 8 (required by some providers).
|
||||
// 1200×632 is the closest 8-aligned pair to the standard OG image size (1200×630).
|
||||
private const DEFAULT_WIDTH = 1200;
|
||||
private const DEFAULT_HEIGHT = 632;
|
||||
|
||||
/** @var PRAutoBlogger_Image_Provider_Interface Image gen provider (FLUX.1 etc). */
|
||||
/** @var PRAutoBlogger_Image_Provider_Interface Image gen provider. */
|
||||
private PRAutoBlogger_Image_Provider_Interface $provider;
|
||||
|
||||
/** @var PRAutoBlogger_Image_Prompt_Builder Builds scene + caption from article data. */
|
||||
@@ -248,15 +248,14 @@ class PRAutoBlogger_Image_Pipeline {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a comic caption as a styled figcaption block to post content.
|
||||
* Prepend the comic caption as styled text at the top of the post content.
|
||||
*
|
||||
* Inserts a <figure> block at the top of the post containing the featured
|
||||
* image and a <figcaption> with the comic punchline. Uses inline styles
|
||||
* for portability across themes.
|
||||
* Only inserts the caption — NOT the image. The theme already displays the
|
||||
* featured image, so embedding it again would cause a duplicate.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param int $attachment_id Featured image attachment ID.
|
||||
* @param string $caption Caption text (the comic punchline).
|
||||
* @param int $post_id Post ID.
|
||||
* @param int $attachment_id Featured image attachment ID (for meta storage only).
|
||||
* @param string $caption Caption text (the comic punchline).
|
||||
*/
|
||||
private function prepend_caption_to_post( int $post_id, int $attachment_id, string $caption ): void {
|
||||
$post = get_post( $post_id );
|
||||
@@ -264,23 +263,15 @@ class PRAutoBlogger_Image_Pipeline {
|
||||
return;
|
||||
}
|
||||
|
||||
$img_url = wp_get_attachment_url( $attachment_id );
|
||||
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
|
||||
|
||||
// Build a self-contained figure block with the comic image and caption.
|
||||
$figure = sprintf(
|
||||
'<figure class="prautoblogger-comic" style="text-align:center;margin:0 0 2em 0;">'
|
||||
. '<img src="%s" alt="%s" style="max-width:100%%;height:auto;border:2px solid #333;border-radius:4px;" />'
|
||||
. '<figcaption style="font-style:italic;color:#555;margin-top:0.5em;font-size:1.1em;">— "%s"</figcaption>'
|
||||
. '</figure>',
|
||||
esc_url( $img_url ),
|
||||
esc_attr( $alt ),
|
||||
// Caption-only block — the theme handles the featured image display.
|
||||
$caption_html = sprintf(
|
||||
'<p class="prautoblogger-comic-caption" style="text-align:center;font-style:italic;color:#555;font-size:1.1em;margin:0 0 2em 0;">— "%s"</p>',
|
||||
esc_html( $caption )
|
||||
);
|
||||
|
||||
wp_update_post( [
|
||||
'ID' => $post_id,
|
||||
'post_content' => $figure . "\n\n" . $post->post_content,
|
||||
'post_content' => $caption_html . "\n\n" . $post->post_content,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
* Builds image prompts from article content or source data.
|
||||
*
|
||||
* Uses a cheap LLM (via OpenRouter) to distill article content into concise
|
||||
* visual scene descriptions optimised for FLUX.1. Falls back to rule-based
|
||||
* visual scene descriptions optimised for image generation. Falls back to rule-based
|
||||
* synthesis if the LLM call fails, so image generation never blocks on a
|
||||
* prompt-rewriting outage.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user