comment_exists

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

WordPress Version: 6.1

/**
 * WordPress Comment Administration API.
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.3.0
 */
/**
 * Determines if a comment exists based on author and date.
 *
 * For best performance, use `$timezone = 'gmt'`, which queries a field that is properly indexed. The default value
 * for `$timezone` is 'blog' for legacy reasons.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$timezone` parameter.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $comment_author Author of the comment.
 * @param string $comment_date   Date of the comment.
 * @param string $timezone       Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
 * @return string|null Comment post ID on success.
 */
function comment_exists($comment_author, $comment_date, $timezone = 'blog')
{
    global $wpdb;
    $date_field = 'comment_date';
    if ('gmt' === $timezone) {
        $date_field = 'comment_date_gmt';
    }
    return $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments}\n\t\t\tWHERE comment_author = %s AND {$date_field} = %s", stripslashes($comment_author), stripslashes($comment_date)));
}

WordPress Version: 5.5

/**
 * WordPress Comment Administration API.
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.3.0
 */
/**
 * Determine if a comment exists based on author and date.
 *
 * For best performance, use `$timezone = 'gmt'`, which queries a field that is properly indexed. The default value
 * for `$timezone` is 'blog' for legacy reasons.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$timezone` parameter.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $comment_author Author of the comment.
 * @param string $comment_date   Date of the comment.
 * @param string $timezone       Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
 * @return string|null Comment post ID on success.
 */
function comment_exists($comment_author, $comment_date, $timezone = 'blog')
{
    global $wpdb;
    $date_field = 'comment_date';
    if ('gmt' === $timezone) {
        $date_field = 'comment_date_gmt';
    }
    return $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments}\n\t\t\tWHERE comment_author = %s AND {$date_field} = %s", stripslashes($comment_author), stripslashes($comment_date)));
}

WordPress Version: 4.4

/**
 * WordPress Comment Administration API.
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.3.0
 */
/**
 * Determine if a comment exists based on author and date.
 *
 * For best performance, use `$timezone = 'gmt'`, which queries a field that is properly indexed. The default value
 * for `$timezone` is 'blog' for legacy reasons.
 *
 * @since 2.0.0
 * @since 4.4.0 Added the `$timezone` parameter.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $comment_author Author of the comment.
 * @param string $comment_date   Date of the comment.
 * @param string $timezone       Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
 *
 * @return mixed Comment post ID on success.
 */
function comment_exists($comment_author, $comment_date, $timezone = 'blog')
{
    global $wpdb;
    $date_field = 'comment_date';
    if ('gmt' === $timezone) {
        $date_field = 'comment_date_gmt';
    }
    return $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments}\n\t\t\tWHERE comment_author = %s AND {$date_field} = %s", stripslashes($comment_author), stripslashes($comment_date)));
}

WordPress Version: 4.3

/**
 * WordPress Comment Administration API.
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Determine if a comment exists based on author and date.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $comment_author Author of the comment
 * @param string $comment_date Date of the comment
 * @return mixed Comment post ID on success.
 */
function comment_exists($comment_author, $comment_date)
{
    global $wpdb;
    return $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments}\n\t\t\tWHERE comment_author = %s AND comment_date = %s", stripslashes($comment_author), stripslashes($comment_date)));
}

WordPress Version: 4.1

/**
 * WordPress Comment Administration API.
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Determine if a comment exists based on author and date.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $comment_author Author of the comment
 * @param string $comment_date Date of the comment
 * @return mixed Comment post ID on success.
 */
function comment_exists($comment_author, $comment_date)
{
    global $wpdb;
    $comment_author = stripslashes($comment_author);
    $comment_date = stripslashes($comment_date);
    return $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments}\n\t\t\tWHERE comment_author = %s AND comment_date = %s", $comment_author, $comment_date));
}

WordPress Version: 3.7

/**
 * WordPress Comment Administration API.
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * Determine if a comment exists based on author and date.
 *
 * @since 2.0.0
 * @uses $wpdb
 *
 * @param string $comment_author Author of the comment
 * @param string $comment_date Date of the comment
 * @return mixed Comment post ID on success.
 */
function comment_exists($comment_author, $comment_date)
{
    global $wpdb;
    $comment_author = stripslashes($comment_author);
    $comment_date = stripslashes($comment_date);
    return $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments}\n\t\t\tWHERE comment_author = %s AND comment_date = %s", $comment_author, $comment_date));
}