Make WordPress Core


Ignore:
Timestamp:
08/19/2020 01:55:12 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Comments: Make sure the comment data passed to the preprocess_comment filter includes the comment_agent and comment_author_IP values.

Props zodiac1978, SergeyBiryukov.
Fixes #51044.

File:
1 edited

Legend:

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

    r48748 r48822  
    21892189        $prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0;
    21902190
     2191        if ( ! isset( $commentdata['comment_author_IP'] ) ) {
     2192                $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
     2193        }
     2194
     2195        if ( ! isset( $commentdata['comment_agent'] ) ) {
     2196                $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
     2197        }
     2198
    21912199        /**
    21922200         * Filters a comment's data before it is sanitized and inserted into the database.
    21932201         *
    21942202         * @since 1.5.0
     2203         * @since 5.6.0 Comment data includes the `comment_agent` and `comment_author_IP` values.
    21952204         *
    21962205         * @param array $commentdata Comment data.
    … …  
    22122221        $commentdata['comment_parent'] = ( 'approved' === $parent_status || 'unapproved' === $parent_status ) ? $commentdata['comment_parent'] : 0;
    22132222
    2214         if ( ! isset( $commentdata['comment_author_IP'] ) ) {
    2215                 $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
    2216         }
    22172223        $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] );
    22182224
    2219         if ( ! isset( $commentdata['comment_agent'] ) ) {
    2220                 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
    2221         }
    22222225        $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 );
    22232226
Note: See TracChangeset for help on using the changeset viewer.