| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | |
| 9 | 9 | use WPDeveloper\BetterDocs\Utils\Base; |
| 10 | 10 | use WPDeveloper\BetterDocs\Core\Settings; |
| 11 | 11 | use WPDeveloper\BetterDocs\Utils\AIHelper; |
| 12 | +use WPDeveloper\BetterDocs\Utils\AIUsage; | |
| 12 | 13 | |
| 13 | 14 | class ArticleSummary extends Base { |
| 14 | 15 | |
| 15 | 16 | public $settings; |
| @@ -127,8 +128,11 @@ | ||
| 127 | 128 | wp_send_json_error( $summary->get_error_message() ); |
| 128 | 129 | wp_die(); |
| 129 | 130 | } |
| 130 | 131 | |
| 132 | + // Count only fresh generations (cache hits returned earlier). | |
| 133 | + AIUsage::record( 'article_summary', $post_id ); | |
| 134 | + | |
| 131 | 135 | // Clean up the summary content and sanitize the AI output with wp_kses_post() |
| 132 | 136 | // before it is stored or returned. This strips dangerous attributes/tags |
| 133 | 137 | // (onerror, <script>, etc.) even if a prompt injection ever succeeds, while |
| 134 | 138 | // preserving safe formatting like <p>/<strong>/<ul>. (fbs-82814) |
| @@ -158,9 +162,9 @@ | ||
| 158 | 162 | } |
| 159 | 163 | |
| 160 | 164 | try { |
| 161 | 165 | if ( ! $this->ai_helper->has_api_key() ) { |
| 162 | - return new \WP_Error( 'no_api_key', 'OpenAI API key is not configured. Please add your API key in BetterDocs settings.' ); | |
| 166 | + return new \WP_Error( 'no_api_key', 'AI API key is not configured. Please add your API key in BetterDocs settings.' ); | |
| 163 | 167 | } |
| 164 | 168 | |
| 165 | 169 | // Prepare content for AI processing |
| 166 | 170 | $prepared_content = $this->ai_helper->prepare_content_for_ai( $content, 4000 ); |