Make WordPress Core


Ignore:
Timestamp:
02/17/2021 01:06:43 PM (6 years ago)
Author:
johnbillion
Message:

Comments: Revert the introduction of the opt-in comment approval notification feature.

This reverts the following commits: [50113], [50112], [50109].

See #33717

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-walker-comment.php

    r50109 r50375  
    4040                'id'     => 'comment_ID',
    4141        );
    42 
    43         /**
    44          * Whether the comment approval notification opt-in form or message needs to be
    45          * output automatically.
    46          *
    47          * @since 5.7.0
    48          *
    49          * @var bool
    50          */
    51         protected $needs_comment_approval_notification_output = true;
    5242
    5343        /**
    … …  
    266256         * Filters the comment text.
    267257         *
    268          *   - Removes links from the pending comment's text if the commenter did not consent
    269          *     to the comment cookies
    270          *   - Prepends the approval notification opt-in form or message to pending comments
     258         * Removes links from the pending comment's text if the commenter did not consent
     259         * to the comment cookies.
    271260         *
    272261         * @since 5.4.2
    273          * @since 5.7.0 Comment approval notification opt-in form is now automatically
    274          *              appended if necessary.
    275262         *
    276263         * @param string          $comment_text Text of the current comment.
    … …  
    286273                }
    287274
    288                 /*
    289                  * Checks if we need to output the comment approval notification opt-in form.
    290                  */
    291                 if ( $this->needs_comment_approval_notification_output ) {
    292                         $comment_text = $this->comment_approval_notification_form( $comment ) . "\n" . $comment_text;
    293                 }
    294 
    295                 $this->needs_comment_approval_notification_output = true;
    296 
    297275                return $comment_text;
    298         }
    299 
    300         /**
    301          * Outputs the awaiting moderation text.
    302          *
    303          * @since 5.7.0
    304          *
    305          * @param WP_Comment $comment Comment to display.
    306          */
    307         protected function awaiting_moderation_text( $comment ) {
    308                 if ( '0' !== $comment->comment_approved ) {
    309                         return;
    310                 }
    311 
    312                 $commenter = wp_get_current_commenter();
    313 
    314                 if ( $commenter['comment_author_email'] ) {
    315                         $moderation_note = __( 'Your comment is awaiting moderation.' );
    316                 } else {
    317                         $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
    318                 }
    319 
    320                 printf(
    321                         '<em class="comment-awaiting-moderation">%s</em>',
    322                         esc_html( $moderation_note )
    323                 );
    324         }
    325 
    326         /**
    327          * Gets the comment approval notification opt-in form or message for a pending comment.
    328          *
    329          * @since 5.7.0
    330          *
    331          * @param WP_Comment $comment Comment to display.
    332          * @return string HTML output.
    333          */
    334         protected function comment_approval_notification_form( $comment ) {
    335                 $comment_approval_output = '';
    336 
    337                 if ( '0' === $comment->comment_approved && has_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' ) ) {
    338                         if ( get_comment_meta( $comment->comment_ID, '_wp_comment_author_notification_optin', true ) ) {
    339                                 $comment_approval_output = sprintf(
    340                                         '<p><em class="wp-comment-approved-notification-optedin">%s</em></p>',
    341                                         esc_html__( 'You will receive an email when your comment is approved.' )
    342                                 );
    343                         } else {
    344                                 $comment_approval_output = sprintf(
    345                                         '<form action="%1$s" method="post">
    346                                                 <p>
    347                                                         <input type="checkbox" id="wp-comment-approved-notification-optin" name="wp-comment-approved-notification-optin">
    348                                                         <label for="wp-comment-approved-notification-optin">
    349                                                                 %2$s
    350                                                         </label>
    351                                                 </p>
    352                                                 <input type="hidden" name="comment_ID" value="%3$s">
    353                                                 <input type="hidden" name="moderation-hash" value="%4$s">
    354                                                 <input type="submit" class="button" value="%5$s">
    355                                         </form>',
    356                                         esc_url( site_url( '/wp-comments-post.php' ) ),
    357                                         esc_html__( 'I want to be notified by email when my comment is approved.' ),
    358                                         absint( $comment->comment_ID ),
    359                                         wp_hash( $comment->comment_date_gmt ),
    360                                         esc_html_x( 'Save', 'comment approval notification form' )
    361                                 );
    362                         }
    363                 }
    364 
    365                 // Disable the backcompat output.
    366                 $this->needs_comment_approval_notification_output = false;
    367 
    368                 // Return the approval notification opt-in form.
    369                 return $comment_approval_output;
    370276        }
    371277
    … …  
    392298                $commenter          = wp_get_current_commenter();
    393299                $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
     300
     301                if ( $commenter['comment_author_email'] ) {
     302                        $moderation_note = __( 'Your comment is awaiting moderation.' );
     303                } else {
     304                        $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' );
     305                }
    394306                ?>
    395307                <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
    … …  
    417329                        ?>
    418330                </div>
    419 
    420                 <?php
    421                 // Output the comment moderation feedback if needed.
    422                 $this->awaiting_moderation_text( $comment );
    423 
    424                 // Output the comment approval notification opt-in form if needed.
    425                 echo $this->comment_approval_notification_form( $comment );
    426                 ?>
     331                <?php if ( '0' == $comment->comment_approved ) : ?>
     332                <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
     333                <br />
     334                <?php endif; ?>
    427335
    428336                <div class="comment-meta commentmetadata">
    … …  
    494402                $commenter          = wp_get_current_commenter();
    495403                $show_pending_links = ! empty( $commenter['comment_author'] );
     404
     405                if ( $commenter['comment_author_email'] ) {
     406                        $moderation_note = __( 'Your comment is awaiting moderation.' );
     407                } else {
     408                        $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' );
     409                }
    496410                ?>
    497411                <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
    … …  
    537451                                        </div><!-- .comment-metadata -->
    538452
    539                                         <?php
    540                                         // Output the comment moderation feedback if needed.
    541                                         $this->awaiting_moderation_text( $comment );
    542 
    543                                         // Output the comment approval notification opt-in form if needed.
    544                                         echo $this->comment_approval_notification_form( $comment );
    545                                         ?>
     453                                        <?php if ( '0' == $comment->comment_approved ) : ?>
     454                                        <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
     455                                        <?php endif; ?>
    546456                                </footer><!-- .comment-meta -->
    547457
Note: See TracChangeset for help on using the changeset viewer.