rest_is_ip_address

Determines if an IP address is valid.

Description

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

Handles both IPv4 and IPv6 addresses.

Returns (string|false)

The valid IP address, otherwise false.

Parameters (1)

0. $ip (string)
IP address.

Usage

  1. if ( !function_exists( 'rest_is_ip_address' ) ) { 
  2. require_once ABSPATH . WPINC . '/rest-api.php'; 
  3.  
  4. // IP address. 
  5. $ip = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = rest_is_ip_address($ip); 
  9.  

Defined (1)

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

/wp-includes/rest-api.php  
  1. function rest_is_ip_address( $ip ) { 
  2. $ipv4_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( $ipv4_pattern, $ip ) && ! Requests_IPv6::check_ipv6( $ip ) ) { 
  5. return false; 
  6.  
  7. return $ip;