get_comment_link

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

WordPress Version: 6.3

/**
 * Retrieves the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Optional. Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to get_page_of_comment().
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to get_page_of_comment().
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value.
 *                                 If provided, this value overrides any value calculated from `$page`
 *                                 and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Back-compat.
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $comment_link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $comment_link = trailingslashit($comment_link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $comment_link = user_trailingslashit($comment_link, 'comment');
        } elseif ($cpage) {
            $comment_link = add_query_arg('cpage', $cpage, $comment_link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $comment_link = user_trailingslashit($comment_link, 'comment');
    }
    $comment_link = $comment_link . '#comment-' . $comment->comment_ID;
    /**
     * Filters the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $comment_link The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment      The current comment object.
     * @param array      $args         An array of arguments to override the defaults.
     * @param int        $cpage        The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $comment_link, $comment, $args, $cpage);
}

WordPress Version: 6.2

/**
 * Retrieves the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Optional. Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to get_page_of_comment().
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to get_page_of_comment().
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value.
 *                                 If provided, this value overrides any value calculated from `$page`
 *                                 and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Back-compat.
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filters the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 5.4

/**
 * Retrieves the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to get_page_of_comment().
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to get_page_of_comment().
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value.
 *                                 If provided, this value overrides any value calculated from `$page`
 *                                 and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Back-compat.
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filters the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 5.3

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to get_page_of_comment().
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to get_page_of_comment().
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value.
 *                                 If provided, this value overrides any value calculated from `$page`
 *                                 and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Back-compat.
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filters the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 4.6

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to get_page_of_comment().
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to get_page_of_comment().
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value.
 *                                 If provided, this value overrides any value calculated from `$page`
 *                                 and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Back-compat.
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filters the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 4.5

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to {@see get_page_of_comment()}.
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to {@see get_page_of_comment()}.
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value. If provided, this
 *                                 value overrides any value calculated from `$page` and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 4.1

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to {@see get_page_of_comment()}.
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to {@see get_page_of_comment()}.
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value. If provided, this
 *                                 value overrides any value calculated from `$page` and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        $default_comments_page = get_option('default_comments_page');
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage && get_option('page_comments')) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 4.4

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite
 * @global bool       $in_comment_loop
 *
 * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 * @param array               $args {
 *     An array of optional arguments to override the defaults.
 *
 *     @type string     $type      Passed to {@see get_page_of_comment()}.
 *     @type int        $page      Current page of comments, for calculating comment pagination.
 *     @type int        $per_page  Per-page value for comment pagination.
 *     @type int        $max_depth Passed to {@see get_page_of_comment()}.
 *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value. If provided, this
 *                                 value overrides any value calculated from `$page` and `$per_page`.
 * }
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'cpage' => null);
    $args = wp_parse_args($args, $defaults);
    $link = get_permalink($comment->comment_post_ID);
    // The 'cpage' param takes precedence.
    if (!is_null($args['cpage'])) {
        $cpage = $args['cpage'];
        // No 'cpage' is provided, so we calculate one.
    } else {
        if ('' === $args['per_page'] && get_option('page_comments')) {
            $args['per_page'] = get_option('comments_per_page');
        }
        if (empty($args['per_page'])) {
            $args['per_page'] = 0;
            $args['page'] = 0;
        }
        $cpage = $args['page'];
        if ('' == $cpage) {
            if (!empty($in_comment_loop)) {
                $cpage = get_query_var('cpage');
            } else {
                // Requires a database hit, so we only do it when we can't figure out from context.
                $cpage = get_page_of_comment($comment->comment_ID, $args);
            }
        }
        /*
         * If the default page displays the oldest comments, the permalinks for comments on the default page
         * do not need a 'cpage' query var.
         */
        $default_comments_page = get_option('default_comments_page');
        if ('oldest' === get_option('default_comments_page') && 1 === $cpage) {
            $cpage = '';
        }
    }
    if ($cpage) {
        if ($wp_rewrite->using_permalinks()) {
            if ($cpage) {
                $link = trailingslashit($link) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
            }
            $link = user_trailingslashit($link, 'comment');
        } elseif ($cpage) {
            $link = add_query_arg('cpage', $cpage, $link);
        }
    }
    if ($wp_rewrite->using_permalinks()) {
        $link = user_trailingslashit($link, 'comment');
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$cpage` parameter.
     *
     * @see get_page_of_comment()
     *
     * @param string     $link    The comment permalink with '#comment-$id' appended.
     * @param WP_Comment $comment The current comment object.
     * @param array      $args    An array of arguments to override the defaults.
     * @param int        $cpage   The calculated 'cpage' value.
     */
    return apply_filters('get_comment_link', $link, $comment, $args, $cpage);
}

WordPress Version: 4.3

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 *
 * @see get_page_of_comment()
 *
 * @global WP_Rewrite $wp_rewrite
 * @global bool       $in_comment_loop
 *
 * @param mixed $comment Comment to retrieve. Default current comment.
 * @param array $args    Optional. An array of arguments to override the defaults.
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    if ('' === $args['per_page'] && get_option('page_comments')) {
        $args['per_page'] = get_option('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page']) {
        if ('' == $args['page']) {
            $args['page'] = (!empty($in_comment_loop)) ? get_query_var('cpage') : get_page_of_comment($comment->comment_ID, $args);
        }
        if ($wp_rewrite->using_permalinks()) {
            $link = user_trailingslashit(trailingslashit(get_permalink($comment->comment_post_ID)) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment');
        } else {
            $link = add_query_arg('cpage', $args['page'], get_permalink($comment->comment_post_ID));
        }
    } else {
        $link = get_permalink($comment->comment_post_ID);
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     *
     * @see get_page_of_comment()
     *
     * @param string $link    The comment permalink with '#comment-$id' appended.
     * @param object $comment The current comment object.
     * @param array  $args    An array of arguments to override the defaults.
     */
    return apply_filters('get_comment_link', $link, $comment, $args);
}

WordPress Version: 4.2

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 *
 * @see get_page_of_comment()
 *
 * @param mixed $comment Comment to retrieve. Default current comment.
 * @param array $args    Optional. An array of arguments to override the defaults.
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    if ('' === $args['per_page'] && get_option('page_comments')) {
        $args['per_page'] = get_option('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page']) {
        if ('' == $args['page']) {
            $args['page'] = (!empty($in_comment_loop)) ? get_query_var('cpage') : get_page_of_comment($comment->comment_ID, $args);
        }
        if ($wp_rewrite->using_permalinks()) {
            $link = user_trailingslashit(trailingslashit(get_permalink($comment->comment_post_ID)) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment');
        } else {
            $link = add_query_arg('cpage', $args['page'], get_permalink($comment->comment_post_ID));
        }
    } else {
        $link = get_permalink($comment->comment_post_ID);
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     *
     * @see get_page_of_comment()
     *
     * @param string $link    The comment permalink with '#comment-$id' appended.
     * @param object $comment The current comment object.
     * @param array  $args    An array of arguments to override the defaults.
     */
    return apply_filters('get_comment_link', $link, $comment, $args);
}

WordPress Version: 3.9

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 *
 * @see get_page_of_comment()
 *
 * @param mixed $comment Comment to retrieve. Default current comment.
 * @param array $args    Optional. An array of arguments to override the defaults.
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $args = array('page' => $args);
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    if ('' === $args['per_page'] && get_option('page_comments')) {
        $args['per_page'] = get_option('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page']) {
        if ('' == $args['page']) {
            $args['page'] = (!empty($in_comment_loop)) ? get_query_var('cpage') : get_page_of_comment($comment->comment_ID, $args);
        }
        if ($wp_rewrite->using_permalinks()) {
            $link = user_trailingslashit(trailingslashit(get_permalink($comment->comment_post_ID)) . 'comment-page-' . $args['page'], 'comment');
        } else {
            $link = add_query_arg('cpage', $args['page'], get_permalink($comment->comment_post_ID));
        }
    } else {
        $link = get_permalink($comment->comment_post_ID);
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     *
     * @see get_page_of_comment()
     *
     * @param string $link    The comment permalink with '#comment-$id' appended.
     * @param object $comment The current comment object.
     * @param array  $args    An array of arguments to override the defaults.
     */
    return apply_filters('get_comment_link', $link, $comment, $args);
}

WordPress Version: 3.7

/**
 * Retrieve the link to a given comment.
 *
 * @since 1.5.0
 *
 * @param mixed $comment Optional. Comment to retrieve. Default current comment.
 * @param array $args    Optional. An array of arguments to override the defaults. @see get_page_of_comment()
 * @return string The permalink to the given comment.
 */
function get_comment_link($comment = null, $args = array())
{
    global $wp_rewrite, $in_comment_loop;
    $comment = get_comment($comment);
    // Backwards compat
    if (!is_array($args)) {
        $page = $args;
        $args = array();
        $args['page'] = $page;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    if ('' === $args['per_page'] && get_option('page_comments')) {
        $args['per_page'] = get_option('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page']) {
        if ('' == $args['page']) {
            $args['page'] = (!empty($in_comment_loop)) ? get_query_var('cpage') : get_page_of_comment($comment->comment_ID, $args);
        }
        if ($wp_rewrite->using_permalinks()) {
            $link = user_trailingslashit(trailingslashit(get_permalink($comment->comment_post_ID)) . 'comment-page-' . $args['page'], 'comment');
        } else {
            $link = add_query_arg('cpage', $args['page'], get_permalink($comment->comment_post_ID));
        }
    } else {
        $link = get_permalink($comment->comment_post_ID);
    }
    $link = $link . '#comment-' . $comment->comment_ID;
    /**
     * Filter the returned single comment permalink.
     *
     * @since 2.8.0
     *
     * @param string $link    The comment permalink with '#comment-$id' appended.
     * @param object $comment The current comment object.
     * @param array  $args    An array of arguments to override the defaults. @see get_page_of_comment()
     */
    return apply_filters('get_comment_link', $link, $comment, $args);
}