get_comment_id_fields

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

WordPress Version: 6.3

/**
 * Retrieves hidden input HTML for replying to comments.
 *
 * @since 3.0.0
 * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support.
 *
 * @param int|WP_Post|null $post Optional. The post the comment is being displayed for.
 *                               Defaults to the current global post.
 * @return string Hidden input HTML for replying to comments.
 */
function get_comment_id_fields($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_id = $post->ID;
    $reply_to_id = _get_comment_reply_id($post_id);
    $comment_id_fields = "<input type='hidden' name='comment_post_ID' value='{$post_id}' id='comment_post_ID' />\n";
    $comment_id_fields .= "<input type='hidden' name='comment_parent' id='comment_parent' value='{$reply_to_id}' />\n";
    /**
     * Filters the returned comment ID fields.
     *
     * @since 3.0.0
     *
     * @param string $comment_id_fields The HTML-formatted hidden ID field comment elements.
     * @param int    $post_id           The post ID.
     * @param int    $reply_to_id       The ID of the comment being replied to.
     */
    return apply_filters('comment_id_fields', $comment_id_fields, $post_id, $reply_to_id);
}

WordPress Version: 6.2

/**
 * Retrieves hidden input HTML for replying to comments.
 *
 * @since 3.0.0
 * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support.
 *
 * @param int|WP_Post|null $post Optional. The post the comment is being displayed for.
 *                               Defaults to the current global post.
 * @return string Hidden input HTML for replying to comments.
 */
function get_comment_id_fields($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return '';
    }
    $post_id = $post->ID;
    $reply_to_id = _get_comment_reply_id($post_id);
    $result = "<input type='hidden' name='comment_post_ID' value='{$post_id}' id='comment_post_ID' />\n";
    $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='{$reply_to_id}' />\n";
    /**
     * Filters the returned comment ID fields.
     *
     * @since 3.0.0
     *
     * @param string $result      The HTML-formatted hidden ID field comment elements.
     * @param int    $post_id     The post ID.
     * @param int    $reply_to_id The ID of the comment being replied to.
     */
    return apply_filters('comment_id_fields', $result, $post_id, $reply_to_id);
}

WordPress Version: 5.5

/**
 * Retrieves hidden input HTML for replying to comments.
 *
 * @since 3.0.0
 *
 * @param int $post_id Optional. Post ID. Defaults to the current post ID.
 * @return string Hidden input HTML for replying to comments.
 */
function get_comment_id_fields($post_id = 0)
{
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    $reply_to_id = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    $result = "<input type='hidden' name='comment_post_ID' value='{$post_id}' id='comment_post_ID' />\n";
    $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='{$reply_to_id}' />\n";
    /**
     * Filters the returned comment ID fields.
     *
     * @since 3.0.0
     *
     * @param string $result      The HTML-formatted hidden ID field comment elements.
     * @param int    $post_id     The post ID.
     * @param int    $reply_to_id The ID of the comment being replied to.
     */
    return apply_filters('comment_id_fields', $result, $post_id, $reply_to_id);
}

WordPress Version: 5.4

/**
 * Retrieves hidden input HTML for replying to comments.
 *
 * @since 3.0.0
 *
 * @param int $id Optional. Post ID. Default current post ID.
 * @return string Hidden input HTML for replying to comments
 */
function get_comment_id_fields($id = 0)
{
    if (empty($id)) {
        $id = get_the_ID();
    }
    $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    $result = "<input type='hidden' name='comment_post_ID' value='{$id}' id='comment_post_ID' />\n";
    $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='{$replytoid}' />\n";
    /**
     * Filters the returned comment id fields.
     *
     * @since 3.0.0
     *
     * @param string $result    The HTML-formatted hidden id field comment elements.
     * @param int    $id        The post ID.
     * @param int    $replytoid The id of the comment being replied to.
     */
    return apply_filters('comment_id_fields', $result, $id, $replytoid);
}

WordPress Version: 4.6

/**
 * Retrieve hidden input HTML for replying to comments.
 *
 * @since 3.0.0
 *
 * @param int $id Optional. Post ID. Default current post ID.
 * @return string Hidden input HTML for replying to comments
 */
function get_comment_id_fields($id = 0)
{
    if (empty($id)) {
        $id = get_the_ID();
    }
    $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    $result = "<input type='hidden' name='comment_post_ID' value='{$id}' id='comment_post_ID' />\n";
    $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='{$replytoid}' />\n";
    /**
     * Filters the returned comment id fields.
     *
     * @since 3.0.0
     *
     * @param string $result    The HTML-formatted hidden id field comment elements.
     * @param int    $id        The post ID.
     * @param int    $replytoid The id of the comment being replied to.
     */
    return apply_filters('comment_id_fields', $result, $id, $replytoid);
}

WordPress Version: 3.7

/**
 * Retrieve hidden input HTML for replying to comments.
 *
 * @since 3.0.0
 *
 * @param int $id Optional. Post ID. Default current post ID.
 * @return string Hidden input HTML for replying to comments
 */
function get_comment_id_fields($id = 0)
{
    if (empty($id)) {
        $id = get_the_ID();
    }
    $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
    $result = "<input type='hidden' name='comment_post_ID' value='{$id}' id='comment_post_ID' />\n";
    $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='{$replytoid}' />\n";
    /**
     * Filter the returned comment id fields.
     *
     * @since 3.0.0
     *
     * @param string $result    The HTML-formatted hidden id field comment elements.
     * @param int    $id        The post ID.
     * @param int    $replytoid The id of the comment being replied to.
     */
    return apply_filters('comment_id_fields', $result, $id, $replytoid);
}