get_comment_class

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

WordPress Version: 6.4

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|string[] $css_class  Optional. One or more classes to add to the class list.
 *                                    Default empty.
 * @param int|WP_Comment  $comment_id Optional. Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post     $post       Optional. Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($css_class = '', $comment_id = null, $post = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $_post = get_post($post);
        if ($_post) {
            if ($comment->user_id === $_post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    ++$comment_alt;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        ++$comment_thread_alt;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($css_class)) {
        if (!is_array($css_class)) {
            $css_class = preg_split('#\s+#', $css_class);
        }
        $classes = array_merge($classes, $css_class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string[]    $css_class  An array of additional classes added to the list.
     * @param string      $comment_id The comment ID as a numeric string.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post       The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post);
}

WordPress Version: 6.2

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|string[] $css_class  Optional. One or more classes to add to the class list.
 *                                    Default empty.
 * @param int|WP_Comment  $comment_id Optional. Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post     $post       Optional. Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($css_class = '', $comment_id = null, $post = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $_post = get_post($post);
        if ($_post) {
            if ($comment->user_id === $_post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($css_class)) {
        if (!is_array($css_class)) {
            $css_class = preg_split('#\s+#', $css_class);
        }
        $classes = array_merge($classes, $css_class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string[]    $css_class  An array of additional classes added to the list.
     * @param string      $comment_id The comment ID as a numeric string.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post       The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post);
}

WordPress Version: 6.1

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|string[] $css_class  Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post     $post       Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($css_class = '', $comment_id = null, $post = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $_post = get_post($post);
        if ($_post) {
            if ($comment->user_id === $_post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($css_class)) {
        if (!is_array($css_class)) {
            $css_class = preg_split('#\s+#', $css_class);
        }
        $classes = array_merge($classes, $css_class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string[]    $css_class  An array of additional classes added to the list.
     * @param string      $comment_id The comment ID as a numeric string.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post       The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post);
}

WordPress Version: 5.9

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|string[] $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post     $post_id    Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $post = get_post($post_id);
        if ($post) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string[]    $class      An array of additional classes added to the list.
     * @param string      $comment_id The comment ID as a numeric string.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 5.7

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|string[] $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post     $post_id    Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $post = get_post($post_id);
        if ($post) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string[]    $class      An array of additional classes added to the list.
     * @param int         $comment_id The comment ID.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 5.5

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $post = get_post($post_id);
        if ($post) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment ID.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 5.4

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
 * @return string[] An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback).
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post.
        $post = get_post($post_id);
        if ($post) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments.
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 5.3

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    $user = $comment->user_id ? get_userdata($comment->user_id) : false;
    if ($user) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        $post = get_post($post_id);
        if ($post) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 5.1

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 4.6

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 4.4

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
 * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $classes = array();
    $comment = get_comment($comment_id);
    if (!$comment) {
        return $classes;
    }
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filter the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id);
}

WordPress Version: 4.3

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 *
 * @global int $comment_alt
 * @global int $comment_depth
 * @global int $comment_thread_alt
 *
 * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int          $comment_id Comment ID. Default current comment.
 * @param int|WP_Post  $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $comment = get_comment($comment_id);
    $classes = array();
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filter the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param object   	  $comment    The comment
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment_id, $comment, $post_id);
}

WordPress Version: 4.2

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 *
 * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int          $comment_id Comment ID. Default current comment.
 * @param int|WP_Post  $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $comment = get_comment($comment_id);
    $classes = array();
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // Add classes for comment authors that are registered users.
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filter the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param object   	  $comment    The comment
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment_id, $comment, $post_id);
}

WordPress Version: 4.1

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 *
 * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int          $comment_id Comment ID. Default current comment.
 * @param int|WP_Post  $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $comment = get_comment($comment_id);
    $classes = array();
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // If the comment author has an id (registered), then print the log in name
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        // For all registered users, 'byuser'
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filter the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param object   	  $comment    The comment
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment_id, $comment, $post_id);
}

WordPress Version: 3.9

/**
 * Returns the classes for the comment div as an array.
 *
 * @since 2.7.0
 *
 * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int          $comment_id Comment ID. Default current comment.
 * @param int|WP_Post  $post_id    Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $comment = get_comment($comment_id);
    $classes = array();
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // If the comment author has an id (registered), then print the log in name
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        // For all registered users, 'byuser'
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filter the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
}

WordPress Version: 3.7

/**
 * Returns the classes for the comment div as an array
 *
 * @since 2.7.0
 *
 * @param string|array $class      Optional. One or more classes to add to the class list. Default empty.
 * @param int          $comment_id Optional. Comment ID. Default current comment.
 * @param int|WP_Post  $post_id    Optional. Post ID or WP_Post object. Default current post.
 * @return array An array of classes.
 */
function get_comment_class($class = '', $comment_id = null, $post_id = null)
{
    global $comment_alt, $comment_depth, $comment_thread_alt;
    $comment = get_comment($comment_id);
    $classes = array();
    // Get the comment type (comment, trackback),
    $classes[] = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
    // If the comment author has an id (registered), then print the log in name
    if ($comment->user_id > 0 && $user = get_userdata($comment->user_id)) {
        // For all registered users, 'byuser'
        $classes[] = 'byuser';
        $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
        // For comment authors who are the author of the post
        if ($post = get_post($post_id)) {
            if ($comment->user_id === $post->post_author) {
                $classes[] = 'bypostauthor';
            }
        }
    }
    if (empty($comment_alt)) {
        $comment_alt = 0;
    }
    if (empty($comment_depth)) {
        $comment_depth = 1;
    }
    if (empty($comment_thread_alt)) {
        $comment_thread_alt = 0;
    }
    if ($comment_alt % 2) {
        $classes[] = 'odd';
        $classes[] = 'alt';
    } else {
        $classes[] = 'even';
    }
    $comment_alt++;
    // Alt for top-level comments
    if (1 == $comment_depth) {
        if ($comment_thread_alt % 2) {
            $classes[] = 'thread-odd';
            $classes[] = 'thread-alt';
        } else {
            $classes[] = 'thread-even';
        }
        $comment_thread_alt++;
    }
    $classes[] = "depth-{$comment_depth}";
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    $classes = array_map('esc_attr', $classes);
    /**
     * Filter the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param array       $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment id.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
}