wp_set_comment_cookies

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

WordPress Version: 5.5

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @since 3.4.0
 * @since 4.9.6 The `$cookies_consent` parameter was added.
 *
 * @param WP_Comment $comment         Comment object.
 * @param WP_User    $user            Comment author's user object. The user may not exist.
 * @param bool       $cookies_consent Optional. Comment author's consent to store cookies. Default true.
 */
function wp_set_comment_cookies($comment, $user, $cookies_consent = true)
{
    // If the user already exists, or the user opted out of cookies, don't set cookies.
    if ($user->exists()) {
        return;
    }
    if (false === $cookies_consent) {
        // Remove any existing cookies.
        $past = time() - YEAR_IN_SECONDS;
        setcookie('comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = time() + apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 9.6

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @since 3.4.0
 * @since 4.9.6 The `$cookies_consent` parameter was added.
 *
 * @param WP_Comment $comment         Comment object.
 * @param WP_User    $user            Comment author's user object. The user may not exist.
 * @param boolean    $cookies_consent Optional. Comment author's consent to store cookies. Default true.
 */
function wp_set_comment_cookies($comment, $user, $cookies_consent = true)
{
    // If the user already exists, or the user opted out of cookies, don't set cookies.
    if ($user->exists()) {
        return;
    }
    if (false === $cookies_consent) {
        // Remove any existing cookies.
        $past = time() - YEAR_IN_SECONDS;
        setcookie('comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = time() + apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 9.3

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param WP_Comment $comment Comment object.
 * @param object     $user    Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: .20

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @since 3.4.0
 * @since 4.9.6 The `$cookies_consent` parameter was added.
 *
 * @param WP_Comment $comment         Comment object.
 * @param WP_User    $user            Comment author's user object. The user may not exist.
 * @param boolean    $cookies_consent Optional. Comment author's consent to store cookies. Default true.
 */
function wp_set_comment_cookies($comment, $user, $cookies_consent = true)
{
    // If the user already exists, or the user opted out of cookies, don't set cookies.
    if ($user->exists()) {
        return;
    }
    if (false === $cookies_consent) {
        // Remove any existing cookies.
        $past = time() - YEAR_IN_SECONDS;
        setcookie('comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = time() + apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 9.2

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param WP_Comment $comment Comment object.
 * @param object     $user    Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: .10

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @since 3.4.0
 * @since 4.9.6 The `$cookies_consent` parameter was added.
 *
 * @param WP_Comment $comment         Comment object.
 * @param WP_User    $user            Comment author's user object. The user may not exist.
 * @param boolean    $cookies_consent Optional. Comment author's consent to store cookies. Default true.
 */
function wp_set_comment_cookies($comment, $user, $cookies_consent = true)
{
    // If the user already exists, or the user opted out of cookies, don't set cookies.
    if ($user->exists()) {
        return;
    }
    if (false === $cookies_consent) {
        // Remove any existing cookies.
        $past = time() - YEAR_IN_SECONDS;
        setcookie('comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        setcookie('comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN);
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = time() + apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 4.6

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param WP_Comment $comment Comment object.
 * @param object     $user    Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filters the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 4.4

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param WP_Comment $comment Comment object.
 * @param object     $user    Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filter the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 4.0

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param object $comment Comment object.
 * @param object $user Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filter the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}

WordPress Version: 3.8

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param object $comment Comment object.
 * @param object $user Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filter the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
}

WordPress Version: 3.7

/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param object $comment Comment object.
 * @param object $user Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
}