'property', 'label' => __('Display', 'lime-columns'), 'type' => 'select', 'default' => 'date', 'options' => ['date' => 'Date', 'author' => 'Author', 'comment' => 'Comment']], ['name' => 'date_format', 'label' => __('PHP date format', 'lime-columns'), 'type' => 'text', 'default' => 'Y-m-d H:i:s', 'show_if' => ['property' => 'date']], ]; } public function capabilities(): array { return self::caps(sort: true); } public function sortArgs(Column $column): ?array { global $wpdb; return ['orderby_sql' => "(SELECT MAX(c.comment_date_gmt) FROM {$wpdb->comments} c WHERE c.comment_post_ID = {$wpdb->posts}.ID AND c.comment_approved = '1')"]; } public function value(Column $column, int $id): string { if (!Access::canViewContent($id)) { return ''; } $c = get_comments(['post_id' => $id, 'number' => 1, 'status' => 'approve', 'orderby' => 'comment_date_gmt', 'order' => 'DESC']); if (!$c) { return ''; } return match ((string) $column->setting('property', 'date')) { 'author' => (string) $c[0]->comment_author, 'comment' => Format::words((string) $c[0]->comment_content, 20), default => Format::date((string) $c[0]->comment_date, 'custom', (string) $column->setting('date_format', 'Y-m-d H:i:s')), }; } }