'/usage', 'methods' => 'GET', 'callback' => [$this, 'show'], 'capability' => self::CHAT, 'args' => ['user' => ['type' => 'string', 'default' => 'me', 'enum' => ['me', 'all']]], ]]; } public function show(\WP_REST_Request $request): \WP_REST_Response|\WP_Error { $all = $request->get_param('user') === 'all'; $admin = current_user_can('manage_options'); if ($all && !$admin) { return Errors::forbidden(); } $summary = $this->meter->monthSummary($all ? null : $this->userId()); $caps = ['user' => (int) $this->store->get('governance.user_monthly_tokens')]; if ($admin) { $caps['site'] = (int) $this->store->get('governance.site_monthly_tokens'); } return new \WP_REST_Response($summary + ['caps' => $caps]); } }