` refs): a fixed URL, or a * per-product URL field. Free reads product data only. */ final class SourcesPolicy { use BuildsFreeDefaults; /** * Whether a web page source's fetched content (a fixed URL, or a * per-product URL field) reaches a run, instead of being dropped before * the prompt. {@see \AIPT\Premium\ContentStructure\WebSourcesService} is * the sole registrant of this filter. * * @return bool */ public function webPageSourcesAllowed(): bool { return (bool) apply_filters( 'aipt_content_structure_web_sources_enabled', false ); } /** * Disable every enabled `src:` item in the shared sources policy when * this site may not use web page sources. Covers both source kinds alike * ('url' and 'product_url_field' — the ref alone carries no kind, see * `Core\ContentStructure\Storage\SourceStore`), since both resolve * through the same `src:` ref shape. The 'product' pseudo-ref * (product data) is never touched, and a source row itself is never * deleted or edited by this clamp — only this run's copy of the * definition is affected. * * Disabling the item here is the entire enforcement: * `ExecutionContextBuilder::buildSourcesAndDecisions()` only ever passes * `enabled`-true `src:*` ids to the web page source service's * `contentForSubject()`, so a non-entitled run never fetches, parses or * includes a disabled source's content either. * * @param array &$definition Clamped definition (mutated in place). * @param array &$applied Accumulated appliedFreeDefaults entries. * @return void */ public function clamp( array &$definition, array &$applied ): void { if ( $this->webPageSourcesAllowed() ) { return; } if ( ! isset( $definition['sources']['items'] ) || ! is_array( $definition['sources']['items'] ) ) { return; } $dropped = false; $kept = array(); foreach ( $definition['sources']['items'] as $item ) { $ref = is_array( $item ) ? (string) ( $item['ref'] ?? '' ) : ''; if ( is_array( $item ) && ! empty( $item['enabled'] ) && 1 === preg_match( '/^src:\d+$/', $ref ) ) { $dropped = true; $item['enabled'] = false; } $kept[] = $item; } if ( ! $dropped ) { return; } $definition['sources']['items'] = $kept; $applied[] = $this->freeDefault( 'sources:webPages', 'contentStructureWebSources', __( 'A web page source was skipped, so your product data was used instead.', 'ai-product-tools' ), __( 'web page sources', 'ai-product-tools' ) ); } }