/**
 * Generates the reply URL based on its position (`menu_order` field).
 *
 * @since  1.0.0
 * @access public
 * @param  int     $reply_id
 * @return string
 */
function mb_generate_reply_url($reply_id = 0)
{
    $reply_id = mb_get_reply_id($reply_id);
    /* If reply is not published, return empty string. */
    if (mb_get_publish_post_status() !== mb_get_reply_status($reply_id)) {
        return '';
    }
    $topic_id = mb_get_reply_topic_id($reply_id);
    /* If no topic ID, return empty string. */
    if (0 >= $topic_id) {
        return '';
    }
    /* Set up our variables. */
    $topic_url = get_permalink($topic_id);
    $per_page = mb_get_replies_per_page();
    $reply_position = mb_get_reply_position($reply_id);
    $reply_hash = "#post-{$reply_id}";
    $reply_page = ceil($reply_position / $per_page);
    /* If viewing page 1, just add the reply hash. */
    if (1 >= $reply_page) {
        $reply_url = user_trailingslashit($topic_url) . $reply_hash;
    } else {
        global $wp_rewrite;
        if ($wp_rewrite->using_permalinks()) {
            $reply_url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . user_trailingslashit($reply_page) . $reply_hash;
        } else {
            $reply_url = add_query_arg('paged', $reply_page, $topic_url) . $reply_hash;
        }
    }
    return $reply_url;
}
function mb_get_thread_position($post_id = 0)
{
    $post_id = mb_get_post_id($post_id);
    $position = mb_is_reply($post_id) ? mb_get_reply_position($post_id) + 1 : 1;
    return apply_filters('mb_get_thread_position', $position);
}
/**
 * Displays the reply position.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $reply_id
 * @return void
 */
function mb_reply_position($reply_id = 0)
{
    echo mb_get_reply_position($reply_id);
}