get_page_of_comment

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

WordPress Version: 6.5

/**
 * Calculates what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_id Comment ID.
 * @param array $args {
 *     Array of optional arguments.
 *
 *     @type string     $type      Limit paginated comments to those matching a given type.
 *                                 Accepts 'comment', 'trackback', 'pingback', 'pings'
 *                                 (trackbacks and pingbacks), or 'all'. Default 'all'.
 *     @type int        $per_page  Per-page count to use when calculating pagination.
 *                                 Defaults to the value of the 'comments_per_page' option.
 *     @type int|string $max_depth If greater than 1, comment page will be determined
 *                                 for the top-level parent `$comment_id`.
 *                                 Defaults to the value of the 'thread_comments_depth' option.
 * }
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_id, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_id);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'orderby' => 'none', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        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);
            }
        }
        /**
         * Filters the arguments used to query comments in get_page_of_comment().
         *
         * @since 5.5.0
         *
         * @see WP_Comment_Query::__construct()
         *
         * @param array $comment_args {
         *     Array of WP_Comment_Query arguments.
         *
         *     @type string $type               Limit paginated comments to those matching a given type.
         *                                      Accepts 'comment', 'trackback', 'pingback', 'pings'
         *                                      (trackbacks and pingbacks), or 'all'. Default 'all'.
         *     @type int    $post_id            ID of the post.
         *     @type string $fields             Comment fields to return.
         *     @type bool   $count              Whether to return a comment count (true) or array
         *                                      of comment objects (false).
         *     @type string $status             Comment status.
         *     @type int    $parent             Parent ID of comment to retrieve children of.
         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
         *                                      will be included in paginated comments.
         * }
         */
        $comment_args = apply_filters('get_page_of_comment_query_args', $comment_args);
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = (int) ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_id` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_id ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_id);
}

WordPress Version: 6.4

/**
 * Calculates what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_id Comment ID.
 * @param array $args {
 *     Array of optional arguments.
 *
 *     @type string     $type      Limit paginated comments to those matching a given type.
 *                                 Accepts 'comment', 'trackback', 'pingback', 'pings'
 *                                 (trackbacks and pingbacks), or 'all'. Default 'all'.
 *     @type int        $per_page  Per-page count to use when calculating pagination.
 *                                 Defaults to the value of the 'comments_per_page' option.
 *     @type int|string $max_depth If greater than 1, comment page will be determined
 *                                 for the top-level parent `$comment_id`.
 *                                 Defaults to the value of the 'thread_comments_depth' option.
 * }
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_id, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_id);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'orderby' => 'none', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        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);
            }
        }
        /**
         * Filters the arguments used to query comments in get_page_of_comment().
         *
         * @since 5.5.0
         *
         * @see WP_Comment_Query::__construct()
         *
         * @param array $comment_args {
         *     Array of WP_Comment_Query arguments.
         *
         *     @type string $type               Limit paginated comments to those matching a given type.
         *                                      Accepts 'comment', 'trackback', 'pingback', 'pings'
         *                                      (trackbacks and pingbacks), or 'all'. Default 'all'.
         *     @type int    $post_id            ID of the post.
         *     @type string $fields             Comment fields to return.
         *     @type bool   $count              Whether to return a comment count (true) or array
         *                                      of comment objects (false).
         *     @type string $status             Comment status.
         *     @type int    $parent             Parent ID of comment to retrieve children of.
         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
         *                                      will be included in paginated comments.
         * }
         */
        $comment_args = apply_filters('get_page_of_comment_query_args', $comment_args);
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_id` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_id ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_id);
}

WordPress Version: 6.3

/**
 * Calculates what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_id Comment ID.
 * @param array $args {
 *     Array of optional arguments.
 *
 *     @type string     $type      Limit paginated comments to those matching a given type.
 *                                 Accepts 'comment', 'trackback', 'pingback', 'pings'
 *                                 (trackbacks and pingbacks), or 'all'. Default 'all'.
 *     @type int        $per_page  Per-page count to use when calculating pagination.
 *                                 Defaults to the value of the 'comments_per_page' option.
 *     @type int|string $max_depth If greater than 1, comment page will be determined
 *                                 for the top-level parent `$comment_id`.
 *                                 Defaults to the value of the 'thread_comments_depth' option.
 * }
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_id, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_id);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        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);
            }
        }
        /**
         * Filters the arguments used to query comments in get_page_of_comment().
         *
         * @since 5.5.0
         *
         * @see WP_Comment_Query::__construct()
         *
         * @param array $comment_args {
         *     Array of WP_Comment_Query arguments.
         *
         *     @type string $type               Limit paginated comments to those matching a given type.
         *                                      Accepts 'comment', 'trackback', 'pingback', 'pings'
         *                                      (trackbacks and pingbacks), or 'all'. Default 'all'.
         *     @type int    $post_id            ID of the post.
         *     @type string $fields             Comment fields to return.
         *     @type bool   $count              Whether to return a comment count (true) or array
         *                                      of comment objects (false).
         *     @type string $status             Comment status.
         *     @type int    $parent             Parent ID of comment to retrieve children of.
         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
         *                                      will be included in paginated comments.
         * }
         */
        $comment_args = apply_filters('get_page_of_comment_query_args', $comment_args);
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_id` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_id ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_id);
}

WordPress Version: 6.2

/**
 * Calculates what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_id Comment ID.
 * @param array $args {
 *     Array of optional arguments.
 *
 *     @type string     $type      Limit paginated comments to those matching a given type.
 *                                 Accepts 'comment', 'trackback', 'pingback', 'pings'
 *                                 (trackbacks and pingbacks), or 'all'. Default 'all'.
 *     @type int        $per_page  Per-page count to use when calculating pagination.
 *                                 Defaults to the value of the 'comments_per_page' option.
 *     @type int|string $max_depth If greater than 1, comment page will be determined
 *                                 for the top-level parent `$comment_id`.
 *                                 Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_id, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_id);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        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);
            }
        }
        /**
         * Filters the arguments used to query comments in get_page_of_comment().
         *
         * @since 5.5.0
         *
         * @see WP_Comment_Query::__construct()
         *
         * @param array $comment_args {
         *     Array of WP_Comment_Query arguments.
         *
         *     @type string $type               Limit paginated comments to those matching a given type.
         *                                      Accepts 'comment', 'trackback', 'pingback', 'pings'
         *                                      (trackbacks and pingbacks), or 'all'. Default 'all'.
         *     @type int    $post_id            ID of the post.
         *     @type string $fields             Comment fields to return.
         *     @type bool   $count              Whether to return a comment count (true) or array
         *                                      of comment objects (false).
         *     @type string $status             Comment status.
         *     @type int    $parent             Parent ID of comment to retrieve children of.
         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
         *                                      will be included in paginated comments.
         * }
         */
        $comment_args = apply_filters('get_page_of_comment_query_args', $comment_args);
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_id` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_id ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_id);
}

WordPress Version: 6.1

/**
 * Calculates what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *     Array of optional arguments.
 *
 *     @type string     $type      Limit paginated comments to those matching a given type.
 *                                 Accepts 'comment', 'trackback', 'pingback', 'pings'
 *                                 (trackbacks and pingbacks), or 'all'. Default 'all'.
 *     @type int        $per_page  Per-page count to use when calculating pagination.
 *                                 Defaults to the value of the 'comments_per_page' option.
 *     @type int|string $max_depth If greater than 1, comment page will be determined
 *                                 for the top-level parent `$comment_ID`.
 *                                 Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_ID);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        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);
            }
        }
        /**
         * Filters the arguments used to query comments in get_page_of_comment().
         *
         * @since 5.5.0
         *
         * @see WP_Comment_Query::__construct()
         *
         * @param array $comment_args {
         *     Array of WP_Comment_Query arguments.
         *
         *     @type string $type               Limit paginated comments to those matching a given type.
         *                                      Accepts 'comment', 'trackback', 'pingback', 'pings'
         *                                      (trackbacks and pingbacks), or 'all'. Default 'all'.
         *     @type int    $post_id            ID of the post.
         *     @type string $fields             Comment fields to return.
         *     @type bool   $count              Whether to return a comment count (true) or array
         *                                      of comment objects (false).
         *     @type string $status             Comment status.
         *     @type int    $parent             Parent ID of comment to retrieve children of.
         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
         *                                      will be included in paginated comments.
         * }
         */
        $comment_args = apply_filters('get_page_of_comment_query_args', $comment_args);
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_ID` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_ID ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_ID);
}

WordPress Version: 5.5

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *     Array of optional arguments.
 *
 *     @type string     $type      Limit paginated comments to those matching a given type.
 *                                 Accepts 'comment', 'trackback', 'pingback', 'pings'
 *                                 (trackbacks and pingbacks), or 'all'. Default 'all'.
 *     @type int        $per_page  Per-page count to use when calculating pagination.
 *                                 Defaults to the value of the 'comments_per_page' option.
 *     @type int|string $max_depth If greater than 1, comment page will be determined
 *                                 for the top-level parent `$comment_ID`.
 *                                 Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_ID);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        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);
            }
        }
        /**
         * Filters the arguments used to query comments in get_page_of_comment().
         *
         * @since 5.5.0
         *
         * @see WP_Comment_Query::__construct()
         *
         * @param array $comment_args {
         *     Array of WP_Comment_Query arguments.
         *
         *     @type string $type               Limit paginated comments to those matching a given type.
         *                                      Accepts 'comment', 'trackback', 'pingback', 'pings'
         *                                      (trackbacks and pingbacks), or 'all'. Default 'all'.
         *     @type int    $post_id            ID of the post.
         *     @type string $fields             Comment fields to return.
         *     @type bool   $count              Whether to return a comment count (true) or array
         *                                      of comment objects (false).
         *     @type string $status             Comment status.
         *     @type int    $parent             Parent ID of comment to retrieve children of.
         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
         *                                      will be included in paginated comments.
         * }
         */
        $comment_args = apply_filters('get_page_of_comment_query_args', $comment_args);
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_ID` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_ID ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_ID);
}

WordPress Version: 5.4

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *      Array of optional arguments.
 *      @type string     $type      Limit paginated comments to those matching a given type. Accepts 'comment',
 *                                  'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
 *                                  Default is 'all'.
 *      @type int        $per_page  Per-page count to use when calculating pagination. Defaults to the value of the
 *                                  'comments_per_page' option.
 *      @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
 *                                  `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_ID);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top-level parent if threading is enabled.
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number.
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_ID` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_ID ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_ID);
}

WordPress Version: 5.3

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *      Array of optional arguments.
 *      @type string     $type      Limit paginated comments to those matching a given type. Accepts 'comment',
 *                                  'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
 *                                  Default is 'all'.
 *      @type int        $per_page  Per-page count to use when calculating pagination. Defaults to the value of the
 *                                  'comments_per_page' option.
 *      @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
 *                                  `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    $comment = get_comment($comment_ID);
    if (!$comment) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top level parent if threading is enabled
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_ID` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_ID ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_ID);
}

WordPress Version: 7.1

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *      Array of optional arguments.
 *      @type string     $type      Limit paginated comments to those matching a given type. Accepts 'comment',
 *                                  'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
 *                                  Default is 'all'.
 *      @type int        $per_page  Per-page count to use when calculating pagination. Defaults to the value of the
 *                                  'comments_per_page' option.
 *      @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
 *                                  `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    if (!$comment = get_comment($comment_ID)) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top level parent if threading is enabled
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_ID` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_ID ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_ID);
}

WordPress Version: 4.7

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *      Array of optional arguments.
 *      @type string     $type      Limit paginated comments to those matching a given type. Accepts 'comment',
 *                                  'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
 *                                  Default is 'all'.
 *      @type int        $per_page  Per-page count to use when calculating pagination. Defaults to the value of the
 *                                  'comments_per_page' option.
 *      @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
 *                                  `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    if (!$comment = get_comment($comment_ID)) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top level parent if threading is enabled
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        if ('desc' === get_option('comment_order')) {
            $compare = 'after';
        } else {
            $compare = 'before';
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", $compare => $comment->comment_date_gmt)));
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     * @since 4.7.0 Introduced the `$comment_ID` parameter.
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param int $comment_ID ID of the comment.
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args, $comment_ID);
}

WordPress Version: 4.4

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $comment_ID Comment ID.
 * @param array $args {
 *      Array of optional arguments.
 *      @type string     $type      Limit paginated comments to those matching a given type. Accepts 'comment',
 *                                  'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
 *                                  Default is 'all'.
 *      @type int        $per_page  Per-page count to use when calculating pagination. Defaults to the value of the
 *                                  'comments_per_page' option.
 *      @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
 *                                  `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
 * } *
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    $page = null;
    if (!$comment = get_comment($comment_ID)) {
        return;
    }
    $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
    $args = wp_parse_args($args, $defaults);
    $original_args = $args;
    // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
    if (get_option('page_comments')) {
        if ('' === $args['per_page']) {
            $args['per_page'] = get_query_var('comments_per_page');
        }
        if ('' === $args['per_page']) {
            $args['per_page'] = get_option('comments_per_page');
        }
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        $page = 1;
    }
    if (null === $page) {
        if ('' === $args['max_depth']) {
            if (get_option('thread_comments')) {
                $args['max_depth'] = get_option('thread_comments_depth');
            } else {
                $args['max_depth'] = -1;
            }
        }
        // Find this comment's top level parent if threading is enabled
        if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
            return get_page_of_comment($comment->comment_parent, $args);
        }
        $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
        $comment_query = new WP_Comment_Query();
        $older_comment_count = $comment_query->query($comment_args);
        // No older comments? Then it's page #1.
        if (0 == $older_comment_count) {
            $page = 1;
            // Divide comments older than this one by comments per page to get this comment's page number
        } else {
            $page = ceil(($older_comment_count + 1) / $args['per_page']);
        }
    }
    /**
     * Filters the calculated page on which a comment appears.
     *
     * @since 4.4.0
     *
     * @param int   $page          Comment page.
     * @param array $args {
     *     Arguments used to calculate pagination. These include arguments auto-detected by the function,
     *     based on query vars, system settings, etc. For pristine arguments passed to the function,
     *     see `$original_args`.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Calculated current page.
     *     @type int    $per_page  Calculated number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     * @param array $original_args {
     *     Array of arguments passed to the function. Some or all of these may not be set.
     *
     *     @type string $type      Type of comments to count.
     *     @type int    $page      Current comment page.
     *     @type int    $per_page  Number of comments per page.
     *     @type int    $max_depth Maximum comment threading depth allowed.
     * }
     */
    return apply_filters('get_page_of_comment', (int) $page, $args, $original_args);
}

WordPress Version: 4.3

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @global wpdb $wpdb
 *
 * @param int $comment_ID Comment ID.
 * @param array $args Optional args.
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    if (!$comment = get_comment($comment_ID)) {
        return;
    }
    $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_query_var('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        return 1;
    }
    if ('' === $args['max_depth']) {
        if (get_option('thread_comments')) {
            $args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $args['max_depth'] = -1;
        }
    }
    // Find this comment's top level parent if threading is enabled
    if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
        return get_page_of_comment($comment->comment_parent, $args);
    }
    $allowedtypes = array('comment' => '', 'pingback' => 'pingback', 'trackback' => 'trackback');
    $comtypewhere = ('all' != $args['type'] && isset($allowedtypes[$args['type']])) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
    // Count comments older than this one
    $oldercoms = $wpdb->get_var($wpdb->prepare("SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt));
    // No older comments? Then it's page #1.
    if (0 == $oldercoms) {
        return 1;
    }
    // Divide comments older than this one by comments per page to get this comment's page number
    return ceil(($oldercoms + 1) / $args['per_page']);
}

WordPress Version: 4.1

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 *
 * @param int $comment_ID Comment ID.
 * @param array $args Optional args.
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    if (!$comment = get_comment($comment_ID)) {
        return;
    }
    $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_query_var('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        return 1;
    }
    if ('' === $args['max_depth']) {
        if (get_option('thread_comments')) {
            $args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $args['max_depth'] = -1;
        }
    }
    // Find this comment's top level parent if threading is enabled
    if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
        return get_page_of_comment($comment->comment_parent, $args);
    }
    $allowedtypes = array('comment' => '', 'pingback' => 'pingback', 'trackback' => 'trackback');
    $comtypewhere = ('all' != $args['type'] && isset($allowedtypes[$args['type']])) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
    // Count comments older than this one
    $oldercoms = $wpdb->get_var($wpdb->prepare("SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt));
    // No older comments? Then it's page #1.
    if (0 == $oldercoms) {
        return 1;
    }
    // Divide comments older than this one by comments per page to get this comment's page number
    return ceil(($oldercoms + 1) / $args['per_page']);
}

WordPress Version: 3.7

/**
 * Calculate what page number a comment will appear on for comment paging.
 *
 * @since 2.7.0
 * @uses get_comment() Gets the full comment of the $comment_ID parameter.
 * @uses get_option() Get various settings to control function and defaults.
 * @uses get_page_of_comment() Used to loop up to top level comment.
 *
 * @param int $comment_ID Comment ID.
 * @param array $args Optional args.
 * @return int|null Comment page number or null on error.
 */
function get_page_of_comment($comment_ID, $args = array())
{
    global $wpdb;
    if (!$comment = get_comment($comment_ID)) {
        return;
    }
    $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_query_var('comments_per_page');
    }
    if (empty($args['per_page'])) {
        $args['per_page'] = 0;
        $args['page'] = 0;
    }
    if ($args['per_page'] < 1) {
        return 1;
    }
    if ('' === $args['max_depth']) {
        if (get_option('thread_comments')) {
            $args['max_depth'] = get_option('thread_comments_depth');
        } else {
            $args['max_depth'] = -1;
        }
    }
    // Find this comment's top level parent if threading is enabled
    if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
        return get_page_of_comment($comment->comment_parent, $args);
    }
    $allowedtypes = array('comment' => '', 'pingback' => 'pingback', 'trackback' => 'trackback');
    $comtypewhere = ('all' != $args['type'] && isset($allowedtypes[$args['type']])) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
    // Count comments older than this one
    $oldercoms = $wpdb->get_var($wpdb->prepare("SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt));
    // No older comments? Then it's page #1.
    if (0 == $oldercoms) {
        return 1;
    }
    // Divide comments older than this one by comments per page to get this comment's page number
    return ceil(($oldercoms + 1) / $args['per_page']);
}