diff --git a/wp-comments-post.php b/wp-comments-post.php index 648388f4d1..735ae82306 100644 --- a/wp-comments-post.php +++ b/wp-comments-post.php @@ -90,12 +90,7 @@ $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_emai $comment_id = wp_new_comment( $commentdata ); $comment = get_comment($comment_id); -if ( !$user->ID ) { - $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); -} +do_action('set_comment_cookies', $comment, $user); $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id; $location = apply_filters('comment_post_redirect', $location, $comment); diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 9c58356038..e9171130a6 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -570,6 +570,25 @@ function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value); } +/** + * 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->ID ) + 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); +} + /** * Sanitizes the cookies sent to the user already. * diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 7000c4f747..c17f280c1e 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -240,6 +240,7 @@ add_action( 'do_feed_rss2', 'do_feed_rss2', add_action( 'do_feed_atom', 'do_feed_atom', 10, 1 ); add_action( 'do_pings', 'do_all_pings', 10, 1 ); add_action( 'do_robots', 'do_robots' ); +add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 2 ); add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' ); add_action( 'admin_print_scripts', 'print_head_scripts', 20 ); add_action( 'admin_print_footer_scripts', '_wp_footer_scripts' );