'GET', 'callback' => [$this, 'index'], 'permission_callback' => [Routes::class, 'canManage'], 'args' => ReportWindow::args(), ], ]); } public function index(WP_REST_Request $request): WP_REST_Response|\WP_Error { try { $range = ReportWindow::read($request); } catch (\InvalidArgumentException $refusal) { return ReportWindow::error($refusal); } $custom = ReportWindow::custom($request); $month = $custom ? null : $request->get_param('month'); // Custom dates always carry their comparison, even when they end today. $data = $custom || ReportWindow::complete($request, $range) ? $this->dashboard->compare($range) : $this->dashboard->read($range); if (is_string($month) && $month !== '') $data['month'] = $month; if ($custom) $data['custom'] = true; // Said either way, so a live read (Today) is told apart from a complete one. $data['complete_days'] = ReportWindow::complete($request, $range); $data['today'] = StatDay::today(); return new WP_REST_Response($data); } }