Is there any way how to output wp_list_comments()
into a variable?
Something like $output = wp_list_comments(array('reverse_top_level' => false ), $comments);
I am writing a plugin and it would be handy to use standard WordPress function instead of writing my own.
In the default usage this is impossible due to the nature of the default comment walker which always directly outputs. But the function allows to provide a custom walker.
Further reading about custom walkers:
Codex Class reference
example custom walker class
You could also use output buffering to save it into a variable (this is considered to be dirty):
According to Function Reference for wp_list_comments, you can set the arg Echo to false to return the list.
I imagine the default walker will not echo the code if this is set to false.