Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54482 closed defect (bug) (invalid)

The 'comment_author_IP' will be changed to current admin's IP after editing the comment from wp-admin.

Reported by: lxtx's profile lxtx Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Comments Keywords:
Focuses: administration Cc:

Description

Hi there. The 'comment_author_IP' will be changed to current admin's IP after editing the comment from wp-admin. PLS check it out and fix this issue, THX.

Change History (2)

#1 @lxtx
3 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Got it, https://developer.wordpress.org/reference/hooks/pre_comment_user_ip/#comment-4830, this example has a little problem.

After I change it as below, the issue is fixed.

add_filter( 'pre_comment_user_ip', 'auto_reverse_proxy_pre_comment_user_ip');
function auto_reverse_proxy_pre_comment_user_ip($comment_author_IP) {
    if( is_admin() ){
        return $comment_author_IP;
    }
    
    $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
 
    if (!empty($_SERVER['X_FORWARDED_FOR'])) {
        $X_FORWARDED_FOR = explode(',', $_SERVER['X_FORWARDED_FOR']);
        if (!empty($X_FORWARDED_FOR)) {
            $REMOTE_ADDR = trim($X_FORWARDED_FOR[0]);
        }
    }
 
    /*
    * Some PHP environments will use the $_SERVER['HTTP_X_FORWARDED_FOR'] 
    * variable to capture visitor address information.
    */
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $HTTP_X_FORWARDED_FOR= explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        if (!empty($HTTP_X_FORWARDED_FOR)) {
            $REMOTE_ADDR = trim($HTTP_X_FORWARDED_FOR[0]);
        }
    }
 
    return preg_replace('/[^0-9a-f:\., ]/si', '', $REMOTE_ADDR);
}
Last edited 3 years ago by lxtx (previous) (diff)

#2 @desrosj
3 years ago

  • Component changed from General to Comments
  • Milestone Awaiting Review deleted

Thanks for circling back and explaining the solution to your issue!

@lxtx below that code example on the reference page you linked there is an option to leave feedback. Do you mind just noting the issue with the example that you discovered there for others attempting to use the same example in the future?

Note: See TracTickets for help on using tickets.