Advertisement
businessdad

WooCommerce - Replace IPv6 addresses with an IPv4 address

Sep 5th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. /**
  2.  * Replaces invalid IP addresses, or IPv6 addresses, with a valid IPv4
  3.  * address.
  4.  *
  5.  * @param string visitor_ip The original IP address of the visitor.
  6.  * @return string A valid IPv4 address.
  7.  * @author Aelia <support@aelia.co>
  8.  * @link https://aelia.co
  9.  */
  10. add_filter('wc_aelia_visitor_ip', function($visitor_ip) {
  11.   if(filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
  12.     // IP Address is not an IPv4. In this case, override it with a default IP
  13.     // address
  14.     // Change the IP to the appropriate one
  15.     $visitor_ip = '249.178.22.114';
  16.   }
  17.  
  18.   return $visitor_ip;
  19. }, 10, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement