$args['status']??'approve','number'=>(int)($args['per_page']??20),'paged'=>(int)($args['page']??1)]; if (!empty($args['post_id'])) $q['post_id'] = (int)$args['post_id']; $comments = get_comments($q); return ['comments'=>array_map(fn($c)=>['id'=>(int)$c->comment_ID,'post_id'=>(int)$c->comment_post_ID,'author'=>$c->comment_author,'email'=>$c->comment_author_email,'content'=>$c->comment_content,'status'=>$c->comment_approved,'date'=>$c->comment_date],$comments),'total'=>count($comments)]; } public static function getPendingComments(array $args): array { $comments = get_comments(['status'=>'hold','number'=>(int)($args['per_page']??20)]); return ['comments'=>array_map(fn($c)=>['id'=>(int)$c->comment_ID,'post_id'=>(int)$c->comment_post_ID,'author'=>$c->comment_author,'content'=>$c->comment_content,'date'=>$c->comment_date],$comments),'total'=>count($comments)]; } public static function approveComment(array $args): array { $r = wp_set_comment_status((int)$args['comment_id'],'approve'); if (!$r) throw new \RuntimeException("Failed to approve comment {$args['comment_id']}"); return ['id'=>(int)$args['comment_id'],'approved'=>true]; } public static function spamComment(array $args): array { $r = wp_set_comment_status((int)$args['comment_id'],'spam'); if (!$r) throw new \RuntimeException("Failed to spam comment {$args['comment_id']}"); return ['id'=>(int)$args['comment_id'],'spam'=>true]; } public static function trashComment(array $args): array { $r = wp_trash_comment((int)$args['comment_id']); if (!$r) throw new \RuntimeException("Failed to trash comment {$args['comment_id']}"); return ['id'=>(int)$args['comment_id'],'trashed'=>true]; } public static function deleteComment(array $args): array { $r = wp_delete_comment((int)$args['comment_id'],(bool)($args['force']??false)); if (!$r) throw new \RuntimeException("Failed to delete comment {$args['comment_id']}"); return ['id'=>(int)$args['comment_id'],'deleted'=>true,'permanent'=>(bool)($args['force']??false)]; } public static function createComment(array $args): array { $data = [ 'comment_post_ID' => (int)($args['post_id'] ?? 0), 'comment_content' => $args['content'] ?? '', 'comment_author' => $args['author_name'] ?? 'MCP', 'comment_author_email' => $args['author_email'] ?? '', 'comment_parent' => (int)($args['parent'] ?? 0), 'comment_approved' => $args['status'] ?? 'approve', ]; $id = wp_insert_comment($data); if (!$id) throw new \RuntimeException("Failed to create comment."); return ['id'=>(int)$id,'created'=>true]; } }