wp_list_comments

The timeline below displays how wordpress function wp_list_comments has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Displays a list of comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query::$comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object   $walker            Instance of a Walker class to list comments. Default null.
 *     @type int      $max_depth         The maximum comments depth. Default empty.
 *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
 *                                       'div' will result in no additional list markup. Default 'ul'.
 *     @type callable $callback          Callback function to use. Default null.
 *     @type callable $end-callback      Callback function to use at the end. Default null.
 *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
 *                                       'pingback', 'trackback', 'pings'. Default 'all'.
 *     @type int      $page              Page ID to list comments for. Default empty.
 *     @type int      $per_page          Number of comments to list per page. Default empty.
 *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
 *                                       newest comments first. Default null.
 *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
 *                                       Default 'html5' if the theme supports it.
 *     @type bool     $short_ping        Whether to output short pings. Default false.
 *     @type bool     $echo              Whether to echo the output or return it. Default true.
 * }
 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Default null.
 * @return void|string Void if 'echo' argument is true, or no comments to list.
 *                     Otherwise, HTML list of comments.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments).
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = array(get_current_user_id());
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' !== $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif (1 == $cpage) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' === get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check.
    $parsed_args['page'] = (int) $parsed_args['page'];
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' === get_option('comment_order');
    }
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 6.2

/**
 * Displays a list of comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query::$comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object   $walker            Instance of a Walker class to list comments. Default null.
 *     @type int      $max_depth         The maximum comments depth. Default empty.
 *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
 *                                       'div' will result in no additional list markup. Default 'ul'.
 *     @type callable $callback          Callback function to use. Default null.
 *     @type callable $end-callback      Callback function to use at the end. Default null.
 *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
 *                                       'pingback', 'trackback', 'pings'. Default 'all'.
 *     @type int      $page              Page ID to list comments for. Default empty.
 *     @type int      $per_page          Number of comments to list per page. Default empty.
 *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
 *                                       newest comments first. Default null.
 *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
 *                                       Default 'html5' if the theme supports it.
 *     @type bool     $short_ping        Whether to output short pings. Default false.
 *     @type bool     $echo              Whether to echo the output or return it. Default true.
 * }
 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Default null.
 * @return void|string Void if 'echo' argument is true, or no comments to list.
 *                     Otherwise, HTML list of comments.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments).
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = array(get_current_user_id());
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' !== $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif (1 == $cpage) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' === get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check.
    $parsed_args['page'] = (int) $parsed_args['page'];
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' === get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 6.1

/**
 * Displays a list of comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query::$comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object   $walker            Instance of a Walker class to list comments. Default null.
 *     @type int      $max_depth         The maximum comments depth. Default empty.
 *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
 *                                       'div' will result in no additional list markup. Default 'ul'.
 *     @type callable $callback          Callback function to use. Default null.
 *     @type callable $end-callback      Callback function to use at the end. Default null.
 *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
 *                                       'pingback', 'trackback', 'pings'. Default 'all'.
 *     @type int      $page              Page ID to list comments for. Default empty.
 *     @type int      $per_page          Number of comments to list per page. Default empty.
 *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
 *                                       newest comments first. Default null.
 *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
 *                                       Default 'html5' if the theme supports it.
 *     @type bool     $short_ping        Whether to output short pings. Default false.
 *     @type bool     $echo              Whether to echo the output or return it. Default true.
 * }
 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
 * @return void|string Void if 'echo' argument is true, or no comments to list.
 *                     Otherwise, HTML list of comments.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments).
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = array(get_current_user_id());
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' !== $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif (1 == $cpage) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' === get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check.
    $parsed_args['page'] = (int) $parsed_args['page'];
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' === get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 5.6

/**
 * Displays a list of comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object   $walker            Instance of a Walker class to list comments. Default null.
 *     @type int      $max_depth         The maximum comments depth. Default empty.
 *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
 *                                       'div' will result in no additional list markup. Default 'ul'.
 *     @type callable $callback          Callback function to use. Default null.
 *     @type callable $end-callback      Callback function to use at the end. Default null.
 *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
 *                                       'pingback', 'trackback', 'pings'. Default 'all'.
 *     @type int      $page              Page ID to list comments for. Default empty.
 *     @type int      $per_page          Number of comments to list per page. Default empty.
 *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
 *                                       newest comments first. Default null.
 *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
 *                                       Default 'html5' if the theme supports it.
 *     @type bool     $short_ping        Whether to output short pings. Default false.
 *     @type bool     $echo              Whether to echo the output or return it. Default true.
 * }
 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
 * @return void|string Void if 'echo' argument is true, or no comments to list.
 *                     Otherwise, HTML list of comments.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments).
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = array(get_current_user_id());
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' !== $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif (1 == $cpage) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' === get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check.
    $parsed_args['page'] = (int) $parsed_args['page'];
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' === get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 5.5

/**
 * Displays a list of comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object   $walker            Instance of a Walker class to list comments. Default null.
 *     @type int      $max_depth         The maximum comments depth. Default empty.
 *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
 *                                       'div' will result in no additional list markup. Default 'ul'.
 *     @type callable $callback          Callback function to use. Default null.
 *     @type callable $end-callback      Callback function to use at the end. Default null.
 *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
 *                                       'pingback', 'trackback', 'pings'. Default 'all'.
 *     @type int      $page              Page ID to list comments for. Default empty.
 *     @type int      $per_page          Number of comments to list per page. Default empty.
 *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
 *                                       newest comments first. Default null.
 *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
 *                                       Default 'html5' if the theme supports it.
 *     @type bool     $short_ping        Whether to output short pings. Default false.
 *     @type bool     $echo              Whether to echo the output or return it. Default true.
 * }
 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
 * @return void|string Void if 'echo' argument is true, or no comments to list.
 *                     Otherwise, HTML list of comments.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments).
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = array(get_current_user_id());
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' !== $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' !== $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif (1 == $cpage) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' === get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check.
    $parsed_args['page'] = intval($parsed_args['page']);
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' === get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 5.4

/**
 * Displays a list of comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool   $reverse_top_level Ordering of the listed comments. If true, will display newest comments first.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
 * @return void|string Void if 'echo' argument is true, or no comments to list.
 *                     Otherwise, HTML list of comments.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments).
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = get_current_user_id();
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' != $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif (1 == $cpage) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check.
    $parsed_args['page'] = intval($parsed_args['page']);
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 5.3

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query           WordPress Query object.
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool   $reverse_top_level Ordering of the listed comments. If true, will display newest comments first.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = 0;
    $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $parsed_args An array of arguments for displaying comments.
     */
    $parsed_args = apply_filters('wp_list_comments_args', $parsed_args);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $parsed_args['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($parsed_args['page'] || $parsed_args['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = get_current_user_id();
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' != $parsed_args['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$parsed_args['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$parsed_args['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $parsed_args['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$parsed_args['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$parsed_args['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $parsed_args['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif ($cpage == 1) {
                $parsed_args['cpage'] = '';
            } else {
                $parsed_args['cpage'] = $cpage;
            }
            $parsed_args['page'] = 0;
            $parsed_args['per_page'] = 0;
        }
    }
    if ('' === $parsed_args['per_page'] && get_option('page_comments')) {
        $parsed_args['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($parsed_args['per_page'])) {
        $parsed_args['per_page'] = 0;
        $parsed_args['page'] = 0;
    }
    if ('' === $parsed_args['max_depth']) {
        if (get_option('thread_comments')) {
            $parsed_args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $parsed_args['max_depth'] = -1;
        }
    }
    if ('' === $parsed_args['page']) {
        if (empty($overridden_cpage)) {
            $parsed_args['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $parsed_args['max_depth'];
            $parsed_args['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $parsed_args['per_page'], $threaded) : 1;
            set_query_var('cpage', $parsed_args['page']);
        }
    }
    // Validation check
    $parsed_args['page'] = intval($parsed_args['page']);
    if (0 == $parsed_args['page'] && 0 != $parsed_args['per_page']) {
        $parsed_args['page'] = 1;
    }
    if (null === $parsed_args['reverse_top_level']) {
        $parsed_args['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($parsed_args['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $parsed_args['walker'];
    }
    $output = $walker->paged_walk($_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args);
    $in_comment_loop = false;
    if ($parsed_args['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 5.1

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool   $reverse_top_level Ordering of the listed comments. If true, will display newest comments first.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($r['page'] || $r['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = get_current_user_id();
            } else {
                $unapproved_email = wp_get_unapproved_comment_author_email();
                if ($unapproved_email) {
                    $comment_args['include_unapproved'] = array($unapproved_email);
                }
            }
            $comments = get_comments($comment_args);
            if ('all' != $r['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$r['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$r['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.7

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type bool   $reverse_top_level Ordering of the listed comments. If true, will display newest comments first.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($r['page'] || $r['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = get_current_user_id();
            } else {
                $commenter = wp_get_current_commenter();
                if ($commenter['comment_author_email']) {
                    $comment_args['include_unapproved'] = $commenter['comment_author_email'];
                }
            }
            $comments = get_comments($comment_args);
            if ('all' != $r['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$r['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$r['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.6

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filters the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($r['page'] || $r['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) {
            $comment_args = array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve');
            if (is_user_logged_in()) {
                $comment_args['include_unapproved'] = get_current_user_id();
            } else {
                $commenter = wp_get_current_commenter();
                if ($commenter['comment_author_email']) {
                    $comment_args['include_unapproved'] = $commenter['comment_author_email'];
                }
            }
            $comments = get_comments($comment_args);
            if ('all' != $r['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$r['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$r['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.5

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($r['page'] || $r['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) {
            $comments = get_comments(array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'all'));
            if ('all' != $r['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$r['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$r['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    wp_queue_comments_for_comment_meta_lazyload($_comments);
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: .10

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else if ($r['page'] || $r['per_page']) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) {
            $comments = get_comments(array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'all'));
            if ('all' != $r['type']) {
                $comments_by_type = separate_comments($comments);
                if (empty($comments_by_type[$r['type']])) {
                    return;
                }
                $_comments = $comments_by_type[$r['type']];
            } else {
                $_comments = $comments;
            }
        }
        // Otherwise, fall back on the comments from `$wp_query->comments`.
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                /*
                 * When first page shows oldest comments, post permalink is the same as
                 * the comment permalink.
                 */
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.1

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    /*
     * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
     * perform a separate comment query and allow Walker_Comment to paginate.
     */
    if (is_singular() && ($r['page'] || $r['per_page'])) {
        $current_cpage = get_query_var('cpage');
        if (!$current_cpage) {
            $current_cpage = ('newest' === get_option('default_comments_page')) ? 1 : $wp_query->max_num_comment_pages;
        }
        $current_per_page = get_query_var('comments_per_page');
        if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) {
            $comments = get_comments(array('post_id' => get_queried_object_id(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'all'));
        }
    }
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother.
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                // When first page shows oldest comments, post permalink is the same as the comment permalink.
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.4

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of WP_Comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
        // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother.
        if ($wp_query->max_num_comment_pages) {
            $default_comments_page = get_option('default_comments_page');
            $cpage = get_query_var('cpage');
            if ('newest' === $default_comments_page) {
                $r['cpage'] = $cpage;
                // When first page shows oldest comments, post permalink is the same as the comment permalink.
            } elseif ($cpage == 1) {
                $r['cpage'] = '';
            } else {
                $r['cpage'] = $cpage;
            }
            $r['page'] = 0;
            $r['per_page'] = 0;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.3

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @global WP_Query $wp_query
 * @global int      $comment_alt
 * @global int      $comment_depth
 * @global int      $comment_thread_alt
 * @global bool     $overridden_cpage
 * @global bool     $in_comment_loop
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 4.0

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type object $walker            Instance of a Walker class to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    /**
     * Filter the arguments used in retrieving the comment list.
     *
     * @since 4.0.0
     *
     * @see wp_list_comments()
     *
     * @param array $r An array of arguments for displaying comments.
     */
    $r = apply_filters('wp_list_comments_args', $r);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    if (empty($r['walker'])) {
        $walker = new Walker_Comment();
    } else {
        $walker = $r['walker'];
    }
    $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 3.9

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @see WP_Query->comments
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type string $walker            The Walker class used to list comments. Default null.
 *     @type int    $max_depth         The maximum comments depth. Default empty.
 *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string $callback          Callback function to use. Default null.
 *     @type string $end-callback      Callback function to use at the end. Default null.
 *     @type string $type              Type of comments to list.
 *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    $page              Page ID to list comments for. Default empty.
 *     @type int    $per_page          Number of comments to list per page. Default empty.
 *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
 *     @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
 *     @type string $format            How to format the comments list.
 *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   $short_ping        Whether to output short pings. Default false.
 *     @type bool   $echo              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of comment objects.
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    extract($r, EXTR_SKIP);
    if (empty($walker)) {
        $walker = new Walker_Comment();
    }
    $output = $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 3.8

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type string 'walker'            The Walker class used to list comments. Default null.
 *     @type int    'max_depth'         The maximum comments depth. Default empty.
 *     @type string 'style'             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string 'callback'          Callback function to use. Default null.
 *     @type string 'end-callback'      Callback function to use at the end. Default null.
 *     @type string 'type'              Type of comments to list.
 *                                      Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    'page'              Page ID to list comments for. Default empty.
 *     @type int    'per_page'          Number of comments to list per page. Default empty.
 *     @type int    'avatar_size'       Height and width dimensions of the avatar size. Default 32.
 *     @type string 'reverse_top_level' Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   'reverse_children'  Whether to reverse child comments in the list. Default null.
 *     @type string 'format'            How to format the comments list.
 *                                      Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   'short_ping'        Whether to output short pings. Default false.
 *     @type bool   'echo'              Whether to echo the output or return it. Default true.
 * }
 * @param array $comments Optional. Array of comment objects. @see WP_Query->comments
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    extract($r, EXTR_SKIP);
    if (empty($walker)) {
        $walker = new Walker_Comment();
    }
    $output = $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
    if ($r['echo']) {
        echo $output;
    } else {
        return $output;
    }
}

WordPress Version: 3.7

/**
 * List comments.
 *
 * Used in the comments.php template to list comments for a particular post.
 *
 * @since 2.7.0
 *
 * @param string|array $args {
 *     Optional. Formatting options.
 *
 *     @type string 'walker'            The Walker class used to list comments. Default null.
 *     @type int    'max_depth'         The maximum comments depth. Default empty.
 *     @type string 'style'             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
 *     @type string 'callback'          Callback function to use. Default null.
 *     @type string 'end-callback'      Callback function to use at the end. Default null.
 *     @type string 'type'              Type of comments to list.
 *                                      Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
 *     @type int    'page'              Page ID to list comments for. Default empty.
 *     @type int    'per_page'          Number of comments to list per page. Default empty.
 *     @type int    'avatar_size'       Height and width dimensions of the avatar size. Default 32.
 *     @type string 'reverse_top_level' Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
 *     @type bool   'reverse_children'  Whether to reverse child comments in the list. Default null.
 *     @type string 'format'            How to format the comments list.
 *                                      Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
 *     @type bool   'short_ping'        Whether to output short pings. Default false.
 * }
 * @param array $comments Optional. Array of comment objects. @see WP_Query->comments
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false);
    $r = wp_parse_args($args, $defaults);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type = separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type = separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 != $r['max_depth'];
            $r['page'] = ('newest' == get_option('default_comments_page')) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order');
    }
    extract($r, EXTR_SKIP);
    if (empty($walker)) {
        $walker = new Walker_Comment();
    }
    $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
}