I am trying to set a custom cookie when a visitor submits a comment, but I can not seem to get this working. Here’s what I have in functions.php:
add_action('comment_post', 'ipro_set_comment_cookie');
function ipro_set_comment_cookie($comment) {
setcookie("visitor_name", $comment->comment_author, time()+86400);
setcookie("visitor_email", $comment->comment_author_email, time()+86400);
}
I’ve also tried changing comment_post
to wp_insert_comment
– neither have seemed to work. I am working off of WP’s action references:
http://codex.wordpress.org/Plugin_API/Action_Reference#Comment.2C_Ping.2C_and_Trackback_Actions
…any ideas?
Check out the Database writes in the Filter Reference
Try something like
comment_save_pre
That way it sets on submit (so it calls after your error handling kicks in)
If I understand your question correctly, this should work: