rest_is_ip_address

Determines if an IP address is valid.

Description

(string|false) rest_is_ip_address( (string) $ipv4 ); 

Does not handle IPv6 addresses.

Returns (string|false)

The valid IPv4 address, otherwise false.

Parameters (1)

0. $ipv4 (string)
IP 32-bit address.

Usage

  1. if ( !function_exists( 'rest_is_ip_address' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/vendor/wp-rest-functions.php'; 
  3.  
  4. // IP 32-bit address. 
  5. $ipv4 = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = rest_is_ip_address($ipv4); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/vendor/wp-rest-functions.php  
  1. function rest_is_ip_address( $ipv4 ) { 
  2. $pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.) {3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/'; 
  3.  
  4. if ( ! preg_match( $pattern, $ipv4 ) ) { 
  5. return false; 
  6.  
  7. return $ipv4;