• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_set_comment_cookies() – 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.

You appear to be a bot. Output may be restricted

Description

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.

Usage

wp_set_comment_cookies( $comment, $user, $cookies_consent );

Parameters

$comment
( WP_Comment ) required – Comment object.
$user
( WP_User ) required – Comment author's user object. The user may not exist.
$cookies_consent
( bool ) optional default: 1 – Optional. Comment author's consent to store cookies. Default true.

Returns

void

Source

File name: wordpress/wp-includes/comment.php
Lines:

1 to 31 of 31
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 );
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 21st August 2020

Primary Sidebar

Information

Function name: wp_set_comment_cookies
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/comment.php
File ref: wp-includes/comment.php
Deprecated?: No
API Letters: C,S,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites