Make WordPress Core


Ignore:
Timestamp:
07/01/2015 12:07:28 PM (10 years ago)
Author:
boonebgorges
Message:

Allow 'comment_agent' and 'comment_author_IP' to be set via wp_new_comment().

Props mrutz, wonderboymusic, rachelbaker.
Fixes #14601.

File:
1 edited

Legend:

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

    r32964 r33021  
    22722272 *
    22732273 * @since 1.5.0
     2274 * @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
    22742275 *
    22752276 * @see wp_insert_comment()
     
    23102311    $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;
    23112312
    2312     $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );
    2313     $commentdata['comment_agent']     = isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : '';
     2313    if ( ! isset( $commentdata['comment_author_IP'] ) ) {
     2314        $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
     2315    }
     2316    $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] );
     2317
     2318    if ( ! isset( $commentdata['comment_agent'] ) ) {
     2319        $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT']: '';
     2320    }
     2321    $commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 );
    23142322
    23152323    if ( empty( $commentdata['comment_date'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.