generator key whose admin page fixes what the tool * writes. Tags have no page of their own: the bulk generator handles them. * * @var array */ private const TOOL_GENERATORS = array( 'generate_description' => Generators::DESCRIPTION, 'generate_tags' => Generators::DESCRIPTION, 'generate_title' => Generators::TITLE, 'generate_seo_meta' => Generators::SEO_META, 'generate_faq' => Generators::FAQ, 'generate_alt_text' => Generators::IMAGE_ALT, ); /** * The hook is named literally, not through FILTER, so the release gate * and Plugin Check find this false-default call site. * * @return bool */ public static function enabled(): bool { return (bool) apply_filters( 'aipt_agent_bulk_generation_enabled', false ); } /** * Whether one call may cover $productCount products. * * @param int $productCount Products the call covers. * @return bool */ public static function allows( int $productCount ): bool { return $productCount <= 1 || self::enabled(); } /** * Products per call of the keyless batch tools (no AI call) on this site. * * @return int At least 1. */ public static function keylessBatchLimit(): int { return max( 1, (int) apply_filters( self::KEYLESS_BATCH_FILTER, self::KEYLESS_BATCH_FREE_LIMIT ) ); } /** * Deep link to the free generator page that matches what a refused call * would have written. * * @param string $subject A generator key (description, title, seo_meta, faq, image_alt) or a generate_* tool name. Anything else, or '', gives the description generator. * @return string */ public static function bulkGeneratorUrl( string $subject = '' ): string { $generator = self::TOOL_GENERATORS[ $subject ] ?? $subject; $slug = Generators::adminSlug( $generator ); if ( '' === $slug || Generators::TAXONOMY === $generator ) { $slug = Generators::adminSlug( Generators::DESCRIPTION ); } return admin_url( 'admin.php?page=' . $slug ); } /** * The refusal for a call that spends the store AI key on more than one * product without Business. It names the keyless batch tools, their cap * and the free generator for the refused content, so the agent learns the * way on at once. The WordPress Abilities content runs return it too, and a * client of the MCP Adapter does not have the keyless tools, so the text * says they live on the plugin's own MCP server, and links the generator * page that matches {@see bulkGeneratorUrl()} for the given subject. * * @param string $subject Generator key or generate_* tool name the call would have run; see {@see bulkGeneratorUrl()}. * @return WP_Error */ public static function denial( string $subject = '' ): WP_Error { $limit = self::keylessBatchLimit(); $url = self::bulkGeneratorUrl( $subject ); return PlanDenial::error( self::FEATURE, PlanDenial::PLAN_BUSINESS, sprintf( /* translators: 1: products per call of the keyless batch tools on this site, 2: URL of the free generator page for this content. */ __( 'This call spends the store AI key and covers one product per call on this site. For up to %1$d products per call without the store AI key, use get_content_briefs, validate_content_drafts and apply_content_results on the AI Product Tools MCP server (connected from its AI Agents page). You can also use the free generator for this content: %2$s. The Business plan also covers more products per call here, and background jobs.', 'ai-product-tools' ), $limit, $url ), 'plan_required', array_merge( array( 'limit' => 1, 'keyless_batch_tools' => array( 'get_content_briefs', 'validate_content_drafts', 'apply_content_results' ), 'keyless_batch_limit' => $limit, 'bulk_generator_url' => $url, ), self::upgradeData() ) ); } /** * @return array */ private static function upgradeData(): array { try { $url = FsManager::getInstance()->getUpgradeUrl(); } catch ( Throwable $exception ) { return array(); } return is_string( $url ) && '' !== $url ? array( 'upgrade_url' => $url ) : array(); } }