repository = new ContaiAPILogRepository(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only filter parameter. $this->filter_type = isset( $_GET['filter'] ) ? sanitize_key( wp_unslash( $_GET['filter'] ) ) : 'all'; $this->handle_actions(); } private function handle_actions(): void { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified below. if ( ! isset( $_POST['contai_api_logs_action'] ) ) { return; } check_admin_referer( 'contai_api_logs_action', 'contai_api_logs_nonce' ); if ( isset( $_POST['clear_all_logs'] ) ) { $this->repository->deleteAll(); add_action( 'admin_notices', array( $this, 'render_success_notice' ) ); } elseif ( isset( $_POST['clear_old_logs'] ) ) { $days = isset( $_POST['days'] ) ? absint( wp_unslash( $_POST['days'] ) ) : 7; $deleted = $this->repository->deleteOlderThan( $days ); add_action( 'admin_notices', function () use ( $deleted ) { ?>

repository->count(); $total_errors = $this->repository->countErrors(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only pagination. $current_page = isset( $_GET['paged'] ) ? max( 1, absint( wp_unslash( $_GET['paged'] ) ) ) : 1; $offset = ( $current_page - 1 ) * $this->per_page; if ( $this->filter_type === 'errors' ) { $logs = $this->repository->getErrors( $this->per_page, $offset ); $total = $total_errors; } else { $logs = $this->repository->getAll( $this->per_page, $offset ); $total = $total_logs; } $total_pages = (int) ceil( $total / $this->per_page ); ?>

render_filter_tab( 'all', __( 'All Logs', '1platform-content-ai' ), $total_logs ); ?> render_filter_tab( 'errors', __( 'Errors Only', '1platform-content-ai' ), $total_errors ); ?>

render_log_row( $log ); ?>
1 ) : ?>
render_pagination( $current_page, $total_pages ); ?>
filter_type === $filter; $class = 'contai-tab' . ( $is_active ? ' is-active' : '' ); $url = add_query_arg( array( 'page' => 'contai-content-generator', 'section' => 'api-logs', 'filter' => $filter, ), admin_url( 'admin.php' ) ); ?> = 400 ); $method = $log['method'] ?? ''; $method_badge = $this->getMethodBadge( $method ); $status_badge = $this->getStatusBadge( $log['response_code'] ?? null ); ?> truncate_url( $log['url'] ) ); ?> N/A s —

format_json( $log['request_body'] ) ); ?>

format_json( $log['response_body'] ) ); ?>
'contai-content-generator', 'section' => 'api-logs', 'filter' => $this->filter_type, ), admin_url( 'admin.php' ) ); if ( $current_page > 1 ) : ?> 'contai-badge-info', 'POST' => 'contai-badge-success', 'PUT' => 'contai-badge-warning', 'PATCH' => 'contai-badge-warning', 'DELETE' => 'contai-badge-danger', ); return $map[ strtoupper( $method ) ] ?? 'contai-badge-neutral'; } private function getStatusBadge( ?int $code ): string { if ( $code === null ) { return 'contai-badge-neutral'; } if ( $code >= 200 && $code < 300 ) { return 'contai-badge-success'; } if ( $code >= 400 && $code < 500 ) { return 'contai-badge-warning'; } if ( $code >= 500 ) { return 'contai-badge-danger'; } return 'contai-badge-neutral'; } private function truncate_url( string $url, int $length = 60 ): string { if ( strlen( $url ) <= $length ) { return $url; } return substr( $url, 0, $length ) . '...'; } private function format_json( ?string $json ): string { if ( empty( $json ) ) { return ''; } $decoded = json_decode( $json, true ); if ( json_last_error() === JSON_ERROR_NONE ) { return json_encode( $decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); } return $json; } }