WordPress.org

Make WordPress Core

Ticket #4602: get_ip_address.patch

File get_ip_address.patch, 2.3 KB (added by hovenko, 15 years ago)
  • wp-includes/comment.php

     
    337337       extract($commentdata, EXTR_SKIP);
    338338
    339339       if ( ! isset($comment_author_IP) )
    340                $comment_author_IP = preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] );
     340               $comment_author_IP = preg_replace( '/[^0-9., ]/', '', wp_get_ip_address() );
    341341       if ( ! isset($comment_date) )
    342342               $comment_date = current_time('mysql');
    343343       if ( ! isset($comment_date_gmt) )
     
    392392       $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    393393       $commentdata['user_ID']         = (int) $commentdata['user_ID'];
    394394
    395        $commentdata['comment_author_IP'] = preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] );
     395       $commentdata['comment_author_IP'] = preg_replace( '/[^0-9., ]/', '', wp_get_ip_address() );
    396396       $commentdata['comment_agent']     = $_SERVER['HTTP_USER_AGENT'];
    397397
    398398       $commentdata['comment_date']     = current_time('mysql');
     
    816816               wp_cache_add($comment->comment_ID, $comment, 'comment');
    817817}
    818818
    819 ?>
    820  No newline at end of file
     819?>
  • wp-includes/functions.php

     
    860860       return false;
    861861}
    862862
     863/**
     864 * Finds the IP address of the client. Works behind proxy servers that use
     865 * the X-Forwarded-For header to build a chain of client IP addresses.
     866 *
     867 * @return string
     868 */
     869function wp_get_ip_address() {
     870    if ($ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"]) {
     871        // IP addresses can be chained, separated with commas,
     872        // we want the first one.
     873        if (strpos($ip_address, ',') !== false) {
     874            $ip_address = explode(',', $ip_address);
     875            $ip_address = $ip_address[0];
     876        }
     877    }
     878    else {
     879        $ip_address = $_SERVER["REMOTE_ADDR"];
     880    }
     881
     882    $ip_address = apply_filters('remote_ip_address', $ip_address);
     883
     884    return $ip_address;
     885}
     886
    863887function wp_mkdir_p($target) {
    864888       // from php.net/mkdir user contributed notes
    865889       if (file_exists($target)) {