Make WordPress Core

Changeset 47890


Ignore:
Timestamp:
06/02/2020 09:02:49 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Comments: Rename Walker_Comment::comment_text() to ::filter_comment_text() for clarity.

Ensure the comment object is not null before checking its status.

Follow-up to [47887].

Merges [47889] to the 5.4 branch.
See #49956.

Location:
branches/5.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

  • branches/5.4/src/wp-includes/class-walker-comment.php

    r47888 r47890  
    183183
    184184        if ( 'comment' === $comment->comment_type ) {
    185             add_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
     185            add_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
    186186        }
    187187
     
    201201
    202202        if ( 'comment' === $comment->comment_type ) {
    203             remove_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
     203            remove_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
    204204        }
    205205    }
     
    254254
    255255    /**
    256      * Remove links from the pending comment's text if the commenter has not consent to the comment cookie.
     256     * Filters the comment text.
     257     *
     258     * Removes links from the pending comment's text if the commenter did not consent
     259     * to the comment cookies.
    257260     *
    258261     * @since 5.4.2
    259262     *
    260263     * @param string          $comment_text Text of the current comment.
    261      * @param WP_Comment|null $comment      The comment object.
    262      * @return string                       Text of the current comment.
    263      */
    264     function comment_text( $comment_text, $comment ) {
     264     * @param WP_Comment|null $comment      The comment object. Null if not found.
     265     * @return string Filtered text of the current comment.
     266     */
     267    public function filter_comment_text( $comment_text, $comment ) {
    265268        $commenter          = wp_get_current_commenter();
    266269        $show_pending_links = ! empty( $commenter['comment_author'] );
    267270
    268         if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
    269             return wp_kses( $comment_text, array() );
     271        if ( $comment && '0' == $comment->comment_approved && ! $show_pending_links ) {
     272            $comment_text = wp_kses( $comment_text, array() );
    270273        }
    271274
     
    295298        $commenter          = wp_get_current_commenter();
    296299        $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
     300
    297301        if ( $commenter['comment_author_email'] ) {
    298302            $moderation_note = __( 'Your comment is awaiting moderation.' );
     
    300304            $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
    301305        }
    302 
    303306        ?>
    304307        <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
     
    314317            <?php
    315318            $comment_author = get_comment_author_link( $comment );
     319
    316320            if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
    317321                $comment_author = get_comment_author( $comment );
    318322            }
     323
    319324            printf(
    320325                /* translators: %s: Comment author link. */
     
    391396        $commenter          = wp_get_current_commenter();
    392397        $show_pending_links = ! empty( $commenter['comment_author'] );
     398
    393399        if ( $commenter['comment_author_email'] ) {
    394400            $moderation_note = __( 'Your comment is awaiting moderation.' );
     
    396402            $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' );
    397403        }
    398 
    399404        ?>
    400405        <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
     
    409414                        <?php
    410415                        $comment_author = get_comment_author_link( $comment );
     416
    411417                        if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
    412418                            $comment_author = get_comment_author( $comment );
    413419                        }
     420
    414421                        printf(
    415422                            /* translators: %s: Comment author link. */
  • branches/5.4/src/wp-includes/comment-template.php

    r47366 r47890  
    10171017     *
    10181018     * @param string          $comment_text Text of the current comment.
    1019      * @param WP_Comment|null $comment      The comment object.
     1019     * @param WP_Comment|null $comment      The comment object. Null if not found.
    10201020     * @param array           $args         An array of arguments.
    10211021     */
Note: See TracChangeset for help on using the changeset viewer.