imageAltAttributesAllowed() ) { $this->clampImageAltAttributeData( $definition, $applied ); } } /** * The data sources an Image alt run withholds on this plan. * * @return string[] */ public function lockedSourceRefs(): array { return $this->imageAltAttributesAllowed() ? array() : self::IMAGE_ALT_PREMIUM_SOURCE_REFS; } /** * Replay the EXACT filter `ImageAltController::applyPremiumControls()` * applies (`aipt_image_alt_validate_options`, registered by * `Premium\BulkGenerator\ImageAlt\PremiumImageAltService:: * validateOptions()`), asking for BOTH enrichment halves at once, the * same request shape the legacy controller builds * (`array_merge($options, $free_defaults)` then the filter over * `($controlled, $options)`), so a licensed site is restored exactly * the way the legacy controller restores it. The premium callback * gates both halves behind the one * `PremiumFeatureManager::canUsePremiumFeatures()` check, but each is * read back independently here, the same way the legacy controller * keeps `includeGallery` and `enrichWithAttributes` as two separate * options. * * @return array{includeGallery:bool,enrichWithAttributes:bool} */ private function imageAltEnrichmentOptions(): array { $requested = array( 'includeGallery' => true, 'enrichWithAttributes' => true, ); $free_defaults = array( 'includeGallery' => false, 'enrichWithAttributes' => false, ); $controlled = apply_filters( 'aipt_image_alt_validate_options', array_merge( $requested, $free_defaults ), $requested ); if ( ! is_array( $controlled ) ) { $controlled = $free_defaults; } return array( 'includeGallery' => ! empty( $controlled['includeGallery'] ), 'enrichWithAttributes' => ! empty( $controlled['enrichWithAttributes'] ), ); } /** * Whether a product subject's gallery images (every image beyond its * featured one) may reach a Blueprint Image Alt run. Mirrors the * `includeGallery` half of `aipt_image_alt_validate_options`, the * exact gate the legacy path applies before expanding a product into * more than its featured image (`Service::collect_image_ids()`). * * Public: `ExecutionContextBuilder::imagesFor()` is where a product * subject's image set is actually assembled (this class clamps the * BlueprintDefinition, not subject/image data), so it calls this * directly - the same reason `Context\TermContextBuilder` calls * {@see TaxonomyPolicy::taxonomyAllowedSources()} directly instead of waiting for a * result from `apply()`. * * @return bool */ public function imageAltGalleryAllowed(): bool { return $this->imageAltEnrichmentOptions()['includeGallery']; } /** * Whether product attribute data and the color rule may reach an Image * alt run (the `enrichWithAttributes` half of the same filter). Public * so the Blueprint editor locks what {@see clampImageAltAttributeData()} * withholds. * * @return bool */ public function imageAltAttributesAllowed(): bool { return $this->imageAltEnrichmentOptions()['enrichWithAttributes']; } /** * The `appliedFreeDefaults` entry for a product subject's gallery * images being left out of a non-entitled run. Built here, so its * wording and `PlanDenial` reason code can never drift from the * attribute/color entry {@see clampImageAltAttributeData()} builds * right above it, but added to the result only by a caller that * actually knows a gallery image was dropped for this specific run — * {@see \AIPT\Api\ContentStructure\Engine\ExecutionContextBuilder::imagesFor()} * is where that fact is known (never for an attachment subject or a * product with no gallery images, and never at all on an entitled * site), never this class, which clamps the BlueprintDefinition * before any subject or image data exists. * * @return array{key:string,reason:string} */ public function imageAltGalleryFreeDefault(): array { return $this->freeDefault( 'imageAlt:gallery', 'imageAltEnrichment', __( 'Gallery images were not included in this run, so the featured image was used.', 'ai-product-tools' ), __( 'gallery images', 'ai-product-tools' ) ); } /** * Drop `core:attributes` and every per-attribute `attr:*` ref * ({@see \AIPT\Core\ContentStructure\Domain\FieldCatalog::productValue()} * resolves both to attribute data) from `sources.productFields`, and * turn `structure.rules.includeColor` off: the two things the legacy * `enrichWithAttributes` option feeds a vision prompt (the Premium * build's attribute block on `aipt_image_alt_user_prompt`, and * `ImageAltPrompting::systemPrompt()`'s color line), * replayed for Blueprint's differently-shaped definition. * * Only a merchant-added attribute ref is reported: the default * `core:attributes` field ({@see anyChosenRef()}) and the color rule, * which every starter template turns on and which has nothing to read * without attribute data, are withheld without an entry. * * @param array &$definition Clamped definition (mutated in place). * @param array &$applied Accumulated appliedFreeDefaults entries. * @return void */ private function clampImageAltAttributeData( array &$definition, array &$applied ): void { $removed = $this->stripProductFieldRefs( $definition, static function ( string $ref ): bool { return in_array( $ref, self::IMAGE_ALT_PREMIUM_SOURCE_REFS, true ) || 0 === strpos( $ref, 'attr:' ); } ); if ( ! empty( $definition['structure']['rules']['includeColor'] ) ) { $definition['structure']['rules']['includeColor'] = false; } if ( $this->anyChosenRef( $removed ) ) { $applied[] = $this->freeDefault( 'imageAlt:attributes', 'imageAltEnrichment', __( 'Product attribute data and the color rule were not sent to the AI in this run.', 'ai-product-tools' ), __( 'attribute data and the color rule', 'ai-product-tools' ) ); } } }