namespace, '/' . $this->rest_base . '/traffic', [ 'methods' => 'GET', 'callback' => [$this, 'get_traffic'], 'permission_callback' => [$this, 'check_admin_permissions'], 'args' => [ 'days' => [ 'required' => false, 'type' => 'integer', 'default' => 30, 'minimum' => 1, 'maximum' => 180, ], ], ]); } /** * Admin permission gate (matches the other admin-only endpoints). * * @return bool */ public function check_admin_permissions(): bool { // The capability the Role Manager actually writes against, not // manage_options: `route_map()` maps this prefix to // thinkrank_ai_insights and the matrix offers an "AI Insights" row, so // demanding manage_options here made that grant do nothing (#844). return Capability_Manager::current_user_can('thinkrank_ai_insights'); } /** * AI traffic dashboard summary. * * @param WP_REST_Request $request Request. * @return WP_REST_Response */ public function get_traffic(WP_REST_Request $request): WP_REST_Response { $tracker = new Ai_Traffic_Tracker(); return new WP_REST_Response([ 'success' => true, 'data' => $tracker->summary((int) $request->get_param('days')), ], 200); } }