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:
peptiderepo
2026-04-18 16:08:36 +07:00
parent 650d8df325
commit c8595e05de
9 changed files with 41 additions and 63 deletions

View File

@@ -181,8 +181,8 @@ class PRAutoBlogger_Settings_Fields_Extended {
'section' => 'prautoblogger_images',
'default' => 'openrouter',
'options' => [
'openrouter' => __( 'OpenRouter (FLUX.2 Pro, Seedream, GPT-Image)', 'prautoblogger' ),
'cloudflare' => __( 'Cloudflare Workers AI (FLUX.1 schnell)', 'prautoblogger' ),
'openrouter' => __( 'OpenRouter (multiple models available)', 'prautoblogger' ),
'cloudflare' => __( 'Cloudflare Workers AI', 'prautoblogger' ),
],
'description' => __( 'OpenRouter reuses your existing API key and offers higher-quality models. Cloudflare is cheaper but lower quality.', 'prautoblogger' ),
],
@@ -193,7 +193,7 @@ class PRAutoBlogger_Settings_Fields_Extended {
'section' => 'prautoblogger_images',
'default' => PRAUTOBLOGGER_DEFAULT_IMAGE_MODEL,
'capability' => 'image_generation',
'description' => __( 'Pick a model from your selected provider. FLUX.2 Pro recommended for quality.', 'prautoblogger' ),
'description' => __( 'Pick a model from your selected provider.', 'prautoblogger' ),
'badge' => __( 'Quality', 'prautoblogger' ),
],
[

View File

@@ -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.
}
/**

View File

@@ -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,
] );
}
}

View File

@@ -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.
*

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
/**
* OpenRouter image provider — FLUX.2, Seedream, GPT-Image, Gemini Flash.
* OpenRouter image provider — model-agnostic, works with any image model.
*
* Calls the standard OpenRouter chat/completions endpoint with
* `modalities: ["image"]`. Reuses the same API key and optional

View File

@@ -13,7 +13,7 @@ declare(strict_types=1);
* content generation run, after editorial review, before publish.
* Dependencies: None at interface level — implementations wrap a specific HTTP API.
*
* @see class-cloudflare-image-provider.php — Default implementation (FLUX.1 via Workers AI).
* @see class-cloudflare-image-provider.php — Cloudflare Workers AI implementation.
* @see interface-llm-provider.php — Parallel pattern for LLM providers.
* @see ARCHITECTURE.md — External API Integrations table.
*/

View File

@@ -5,7 +5,7 @@ declare(strict_types=1);
* Contract for a provider-specific AI model registry.
*
* Phase 1 (v1): single implementation for OpenRouter (`class-open-router-model-registry.php`).
* Phase 3: a second implementation wraps Cloudflare Workers AI FLUX model data. A
* Phase 3: a second implementation wraps Cloudflare Workers AI model data. A
* higher-level dispatcher iterates registered registries, calls each with the same
* capability, and unions the results — the per-registry interface stays unchanged.
*