Last active
January 15, 2019 19:18
-
-
Save vanbo/03eb8fb68ef0cdcab8f27d886d1c82a0 to your computer and use it in GitHub Desktop.
WC TrustCommerce: Remove or format IP in requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Removes the 'ip' from TrustCommerce single payment request | |
| add_filter( 'wc_trustcommerce_process_single_payment_request', 'prefix_remove_ip_from_request', 10, 3 ); | |
| function prefix_remove_ip_from_request( $request, $order, $gateway ) { | |
| if ( isset( $request['ip'] ) ) { | |
| unset( $request['ip'] ); | |
| } | |
| return $request; | |
| } | |
| /** | |
| * Fix for error: Array | |
| * ( | |
| * [offenders] => ip | |
| * [error] => badlength | |
| * [status] => baddata | |
| * ) | |
| * | |
| * Retrieves the first IP from format "127.0.0.1, 127.0.0.1" or "127.0.0.1 127.0.0.1" | |
| */ | |
| add_filter( 'trustcommerce_get_user_ip_addr', 'prefix_format_ip_address' ); | |
| function prefix_format_ip_address( $ip ) { | |
| $ip = trim( $ip ); | |
| if ( false !== strpos( $ip, ',' ) ) { | |
| $ips = explode( ',', $ip ); | |
| $ip = trim( array_shift( $ips ) ); | |
| } elseif ( false !== strpos( $ip, ' ' ) ) { | |
| $ips = explode( ' ', $ip ); | |
| $ip = trim( array_shift( $ips ) ); | |
| } | |
| return $ip; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment