wp_set_comment_cookies

Sets the cookies used to store an unauthenticated commentator's identity.

Description

wp_set_comment_cookies( (WP_Comment) $comment, (object) $user ); 

Typically used to recall previous comments by this commentator that are still held in moderation.

Parameters (2)

0. $comment (WP_Comment)
Comment object.
1. $user (object)
Comment author's object.

Usage

  1. if ( !function_exists( 'wp_set_comment_cookies' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Comment object. 
  5. $comment = null; 
  6.  
  7. // Comment author's object. 
  8. $user = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_set_comment_cookies($comment, $user); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function wp_set_comment_cookies($comment, $user) { 
  2. if ( $user->exists() ) 
  3. return; 
  4.  
  5. /** 
  6. * Filters the lifetime of the comment cookie in seconds. 
  7. * @since 2.8.0 
  8. * @param int $seconds Comment cookie lifetime. Default 30000000. 
  9. */ 
  10. $comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); 
  11. $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); 
  12. setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); 
  13. setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); 
  14. setcookie( 'comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure );