clampFaqMode( $definition, $applied ); $this->clampFaqPremiumSources( $definition, $applied ); } /** * The data sources a FAQ run withholds on this plan. * * @return string[] */ public function lockedSourceRefs(): array { return $this->faqAdvancedSourcesAllowed() ? array() : self::FAQ_PREMIUM_SOURCE_REFS; } /** * Whether this site may use a FAQ content mode other than 'both'. * Replays the EXACT filter `FAQGeneratorController::applyFreeDefaults()` * applies (`aipt_faq_validate_options`, registered by * `Premium\FAQ\PremiumFAQFeatures::restorePremiumOptions()`) asking for * 'questions', so a licensed site is restored exactly the way the * legacy controller restores it. Public so the Blueprint editor's * localized data shows the same limit this clamp applies. * * @return bool */ public function faqAdvancedModeAllowed(): bool { $requested = array( 'faqMode' => 'questions' ); $free_defaults = array( 'faqMode' => 'both' ); $controlled = apply_filters( 'aipt_faq_validate_options', array_merge( $requested, $free_defaults ), $requested ); $mode = ( is_array( $controlled ) && is_string( $controlled['faqMode'] ?? null ) ) ? $controlled['faqMode'] : 'both'; return 'both' !== $mode; } /** * Clamp a Blueprint FAQ structure's `mode` ('questions' or 'answers') * back to 'both' when this site is not entitled, mirroring the legacy * generator's own free restriction exactly * (`PremiumFAQFeatures::validateOptions()`: "Restrict FAQ mode to 'both' * only for free users"). * * @param array &$definition Clamped definition (mutated in place). * @param array &$applied Accumulated appliedFreeDefaults entries. * @return void */ private function clampFaqMode( array &$definition, array &$applied ): void { $mode = (string) ( $definition['structure']['mode'] ?? 'both' ); if ( 'both' === $mode || $this->faqAdvancedModeAllowed() ) { return; } $definition['structure']['mode'] = 'both'; $applied[] = $this->freeDefault( 'faq:mode', 'advancedFaqOptions', __( 'This template asked to write only questions or only answers, so questions and answers were written instead.', 'ai-product-tools' ), __( 'writing only questions or only answers', 'ai-product-tools' ) ); } /** * Whether this site may use a FAQ data source beyond the legacy free * default ('product_description'). Replays the EXACT filter * `FAQGeneratorController::applyFreeDefaults()` applies * (`aipt_faq_validate_options`, registered by * `Premium\FAQ\PremiumFAQFeatures::restorePremiumOptions()`) over a * synthetic request asking for every legacy source, the same way * {@see TitlePolicy::titleAdvancedSourcesAllowed()} does for Title. Public so the * Blueprint editor locks the same sources this clamp withholds. * * @return bool */ public function faqAdvancedSourcesAllowed(): bool { $all_sources = array( 'product_description', 'existing_title', 'product_tags', 'product_categories', 'product_attributes' ); $free_default = array( 'product_description' ); $requested = array( 'faqSources' => $all_sources ); $free_defaults = array( 'faqSources' => $free_default ); $controlled = apply_filters( 'aipt_faq_validate_options', array_merge( $requested, $free_defaults ), $requested ); $restored = ( is_array( $controlled ) && is_array( $controlled['faqSources'] ?? null ) ) ? $controlled['faqSources'] : $free_default; return ! empty( array_diff( $restored, $free_default ) ); } /** * Drop FAQ's paid data sources ({@see FAQ_PREMIUM_SOURCE_REFS} and * every `attr:*` ref) from `sources.productFields` when this site is * not entitled. Default fields are withheld without an entry * ({@see anyChosenRef()}). * * @param array &$definition Clamped definition (mutated in place). * @param array &$applied Accumulated appliedFreeDefaults entries. * @return void */ private function clampFaqPremiumSources( array &$definition, array &$applied ): void { if ( $this->faqAdvancedSourcesAllowed() ) { return; } $removed = $this->stripProductFieldRefs( $definition, static function ( string $ref ): bool { return in_array( $ref, self::FAQ_PREMIUM_SOURCE_REFS, true ) || 0 === strpos( $ref, 'attr:' ); } ); if ( $this->anyChosenRef( $removed ) ) { $applied[] = $this->freeDefault( 'faq:sources', 'advancedFaqOptions', __( 'This template used product tags, categories or attributes for FAQs, so the other product fields were used instead.', 'ai-product-tools' ), __( 'more FAQ sources', 'ai-product-tools' ) ); } } }