| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use WP_REST_Request; |
| 6 | 6 | use WPDeveloper\BetterDocs\Core\BaseAPI; |
| 7 | 7 | use WPDeveloper\BetterDocs\Utils\AIHelper; |
| 8 | +use WPDeveloper\BetterDocs\Utils\AIUsage; | |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * REST endpoints powering the BetterDocs "Enhance Docs with AI" editor actions |
| 11 | 12 | * for the `docs` post type: AI-suggested taxonomy terms (doc_category / doc_tag) |
| @@ -71,9 +72,9 @@ | ||
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | public function permission_check() { |
| 74 | 75 | // Gate on edit_others_posts to match the sibling FAQ/Glossary AI endpoints |
| 75 | - // (AIFaq/AIGlossary) and keep Author-role users from spending the OpenAI budget. | |
| 76 | + // (AIFaq/AIGlossary) and keep Author-role users from spending the AI budget. | |
| 76 | 77 | return current_user_can( 'edit_others_posts' ); |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | /** |
| @@ -217,8 +218,13 @@ | ||
| 217 | 218 | 'term_id' => $term ? (int) $term->term_id : null, |
| 218 | 219 | 'is_new' => $term ? false : true |
| 219 | 220 | ); |
| 220 | 221 | } |
| 222 | + | |
| 223 | + // Usage telemetry: a successful AI suggestion run, bucketed by taxonomy | |
| 224 | + // (doc_category/doc_tag/glossaries). An empty result is still a use of the | |
| 225 | + // feature, so record on any successful upstream response. | |
| 226 | + AIUsage::record( 'ai_suggest_terms', $post_id, $taxonomy ); | |
| 221 | 227 | |
| 222 | 228 | return $this->success( array( |
| 223 | 229 | 'taxonomy' => $taxonomy, |
| 224 | 230 | 'suggestions' => $suggestions, |