Skip to content

Commit

Permalink
Merge pull request #3192 from andrewlimaza/fix-pmpro-get-ip
Browse files Browse the repository at this point in the history
Change pmpro_get_ip conditional
  • Loading branch information
ideadude authored Nov 18, 2024
2 parents 738ebdc + 605bfc7 commit 3a62f91
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4449,23 +4449,22 @@ function pmpro_get_ip() {
*/
$address_chain = explode( ',', sanitize_text_field( $_SERVER[ $header ] ) );
$client_ip = trim( $address_chain[0] );

break;
}
}

if ( ! $client_ip ) {
return false;
}

// Check if it's a valid IP address or not.
if ( ! filter_var( $client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) || ! filter_var( $client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) {
return false;
}

// Sanitize the IP
$client_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $client_ip );

// Check if it's a valid IPv4 or IPv6 address.
if ( ! filter_var( $client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) && ! filter_var( $client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) {
return false;
}

return $client_ip;
}

Expand Down

0 comments on commit 3a62f91

Please sign in to comment.