<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[47887] trunk/src: Comments: Ensure that unmoderated comments won't be search indexed.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/47887">47887</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/47887","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>whyisjake</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-06-02 20:10:02 +0000 (Tue, 02 Jun 2020)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Comments: Ensure that unmoderated comments won't be search indexed.
After a comment is submitted, only allow a brief window where the comment is live on the site.
Fixes <a href="https://core.trac.wordpress.org/ticket/49956">#49956</a>.
Props: jonkolbert, ayeshrajans, Asif2BD, peterwilsoncc, imath, audrasjb, jonoaldersonwp, whyisjake.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpcommentspostphp">trunk/src/wp-comments-post.php</a></li>
<li><a href="#trunksrcwpincludesclasswalkercommentphp">trunk/src/wp-includes/class-walker-comment.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcommentqueryphp">trunk/src/wp-includes/class-wp-comment-query.php</a></li>
<li><a href="#trunksrcwpincludesclasswpphp">trunk/src/wp-includes/class-wp.php</a></li>
<li><a href="#trunksrcwpincludescommentphp">trunk/src/wp-includes/comment.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpcommentspostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-comments-post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-comments-post.php 2020-06-02 17:03:06 UTC (rev 47886)
+++ trunk/src/wp-comments-post.php 2020-06-02 20:10:02 UTC (rev 47887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,8 +56,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Add specific query arguments to display the awaiting moderation message.
-if ( 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// If user didn't consent to cookies, add specific query arguments to display the awaiting moderation message.
+if ( ! $cookies_consent && 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $location = add_query_arg(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'unapproved' => $comment->comment_ID,
</span></span></pre></div>
<a id="trunksrcwpincludesclasswalkercommentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-walker-comment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-walker-comment.php 2020-06-02 17:03:06 UTC (rev 47886)
+++ trunk/src/wp-includes/class-walker-comment.php 2020-06-02 20:10:02 UTC (rev 47887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,6 +181,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'comment' === $comment->comment_type ) {
+ add_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ( 'pingback' === $comment->comment_type || 'trackback' === $comment->comment_type ) && $args['short_ping'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> ob_start();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->ping( $comment, $depth, $args );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -194,6 +198,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->comment( $comment, $depth, $args );
</span><span class="cx" style="display: block; padding: 0 10px"> $output .= ob_get_clean();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( 'comment' === $comment->comment_type ) {
+ remove_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -245,6 +253,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Remove links from the pending comment's text if the commenter has not consent to the comment cookie.
+ *
+ * @since 5.4.2
+ *
+ * @param string $comment_text Text of the current comment.
+ * @param WP_Comment|null $comment The comment object.
+ * @return string Text of the current comment.
+ */
+ function comment_text( $comment_text, $comment ) {
+ $commenter = wp_get_current_commenter();
+ $show_pending_links = ! empty( $commenter['comment_author'] );
+
+ if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
+ return wp_kses( $comment_text, array() );
+ }
+
+ return $comment_text;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Outputs a single comment.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.6.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -264,7 +292,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $add_below = 'div-comment';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $commenter = wp_get_current_commenter();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $commenter = wp_get_current_commenter();
+ $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $commenter['comment_author_email'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $moderation_note = __( 'Your comment is awaiting moderation.' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -279,14 +308,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="comment-author vcard">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 0 != $args['avatar_size'] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- echo get_avatar( $comment, $args['avatar_size'] );}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ echo get_avatar( $comment, $args['avatar_size'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- printf(
- /* translators: %s: Comment author link. */
- __( '%s <span class="says">says:</span>' ),
- sprintf( '<cite class="fn">%s</cite>', get_comment_author_link( $comment ) )
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comment_author = get_comment_author_link( $comment );
+ if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
+ $comment_author = get_comment_author( $comment );
+ }
+ printf(
+ /* translators: %s: Comment author link. */
+ __( '%s <span class="says">says:</span>' ),
+ sprintf( '<cite class="fn">%s</cite>', $comment_author )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php if ( '0' == $comment->comment_approved ) : ?>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -354,7 +388,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected function html5_comment( $comment, $depth, $args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $commenter = wp_get_current_commenter();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $commenter = wp_get_current_commenter();
+ $show_pending_links = ! empty( $commenter['comment_author'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $commenter['comment_author_email'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $moderation_note = __( 'Your comment is awaiting moderation.' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -372,11 +407,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- printf(
- /* translators: %s: Comment author link. */
- __( '%s <span class="says">says:</span>' ),
- sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comment_author = get_comment_author_link( $comment );
+ if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
+ $comment_author = get_comment_author( $comment );
+ }
+ printf(
+ /* translators: %s: Comment author link. */
+ __( '%s <span class="says">says:</span>' ),
+ sprintf( '<b class="fn">%s</b>', $comment_author )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </div><!-- .comment-author -->
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -402,18 +441,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div><!-- .comment-content -->
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- comment_reply_link(
- array_merge(
- $args,
- array(
- 'add_below' => 'div-comment',
- 'depth' => $depth,
- 'max_depth' => $args['max_depth'],
- 'before' => '<div class="reply">',
- 'after' => '</div>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( '1' == $comment->comment_approved || $show_pending_links ) {
+ comment_reply_link(
+ array_merge(
+ $args,
+ array(
+ 'add_below' => 'div-comment',
+ 'depth' => $depth,
+ 'max_depth' => $args['max_depth'],
+ 'before' => '<div class="reply">',
+ 'after' => '</div>',
+ )
</ins><span class="cx" style="display: block; padding: 0 10px"> )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- )
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </article><!-- .comment-body -->
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcommentqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-comment-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-comment-query.php 2020-06-02 17:03:06 UTC (rev 47886)
+++ trunk/src/wp-includes/class-wp-comment-query.php 2020-06-02 20:10:02 UTC (rev 47887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -553,10 +553,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Numeric values are assumed to be user ids.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_numeric( $unapproved_identifier ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Otherwise we match against email addresses.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
- $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
+ // Only include requested comment.
+ $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' AND comment_ID = %d )", $unapproved_identifier, (int) $_GET['unapproved'] );
+ } else {
+ // Include all of the author's unapproved comments.
+ $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp.php 2020-06-02 17:03:06 UTC (rev 47886)
+++ trunk/src/wp-includes/class-wp.php 2020-06-02 20:10:02 UTC (rev 47887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -404,6 +404,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_user_logged_in() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $headers = array_merge( $headers, wp_get_nocache_headers() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
+ // Unmoderated comments are only visible for one minute via the moderation hash.
+ $headers['Expires'] = gmdate( 'D, d M Y H:i:s', time() + MINUTE_IN_SECONDS );
+ $headers['Cache-Control'] = 'max-age=60, must-revalidate';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $this->query_vars['error'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $status = (int) $this->query_vars['error'];
</span></span></pre></div>
<a id="trunksrcwpincludescommentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/comment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/comment.php 2020-06-02 17:03:06 UTC (rev 47886)
+++ trunk/src/wp-includes/comment.php 2020-06-02 20:10:02 UTC (rev 47887)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1852,7 +1852,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $comment = get_comment( $comment_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $commenter_email = $comment->comment_author_email;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // The comment will only be viewable by the comment author for 1 minute.
+ $comment_preview_expires = strtotime( $comment->comment_date_gmt . '+1 minute' );
+
+ if ( time() < $comment_preview_expires ) {
+ $commenter_email = $comment->comment_author_email;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>