wp_set_comment_cookies()
Sets the cookies (name, email, url) that are used to identify an unauthenticated user when commenting.
Hooks from the function
Returns
null. Nothing (null).
Usage
wp_set_comment_cookies( $comment, $user, $cookies_consent );
- $comment(WP_Comment) (required)
- Comment object.
- $user(WP_User) (required)
- Comment author's user object. The function will do nothing if the user exists — so that the cookies are saved only to unauthenticated commenters.
- $cookies_consent(true/false)
- Comment author's consent to store cookies.
Default: true
Examples
#1 Setup commenter cookies
By default, cookies are set up using following action in wp-comments-post.php file:
do_action( 'set_comment_cookies', $comment, $user );
But in this example we will set up them separately. For example, when the comment is posted (added) not through the wp-comments-post.php file:
$user = wp_get_current_user(); $comment = get_comment( $id = 255 ); wp_set_comment_cookies( $comment, $user );
Changelog
| Since 3.4.0 | Introduced. |
| Since 4.9.6 | The $cookies_consent parameter was added. |