name(), 'Count comments with FlitAgent', 'counts comments by status (approved, pending, spam, trash, on trashed posts, total) for the whole site or one post_id.', array( 'post_id' => array( 'type' => 'integer', 'minimum' => 1, ), ) ); } /** * Runs the tool. * * @param array $arguments Tool arguments. * @return array * @throws ToolError On invalid arguments. */ public function call( array $arguments ): array { Arguments::only( $arguments, array( 'post_id' ), $this->name() ); $post_id = Arguments::int( $arguments, 'post_id', 0, 1, PHP_INT_MAX ); if ( 0 !== $post_id && ! get_post( $post_id ) ) { throw new ToolError( sprintf( 'Post %d not found.', (int) $post_id ) ); } $counts = (array) wp_count_comments( $post_id ); return array( 'post_id' => 0 === $post_id ? null : $post_id, 'approved' => (int) ( $counts['approved'] ?? 0 ), 'pending' => (int) ( $counts['moderated'] ?? 0 ), 'spam' => (int) ( $counts['spam'] ?? 0 ), 'trash' => (int) ( $counts['trash'] ?? 0 ), 'post_trashed' => (int) ( $counts['post-trashed'] ?? 0 ), 'total' => (int) ( $counts['total_comments'] ?? 0 ), ); } }