rest_is_ip_address

The timeline below displays how wordpress function rest_is_ip_address has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Determines if an IP address is valid.
 *
 * Handles both IPv4 and IPv6 addresses.
 *
 * @since 4.7.0
 *
 * @param string $ip IP address.
 * @return string|false The valid IP address, otherwise false.
 */
function rest_is_ip_address($ip)
{
    $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]?)$/';
    if (!preg_match($ipv4_pattern, $ip) && !WpOrg\Requests\Ipv6::check_ipv6($ip)) {
        return false;
    }
    return $ip;
}

WordPress Version: 5.5

/**
 * Determines if an IP address is valid.
 *
 * Handles both IPv4 and IPv6 addresses.
 *
 * @since 4.7.0
 *
 * @param string $ip IP address.
 * @return string|false The valid IP address, otherwise false.
 */
function rest_is_ip_address($ip)
{
    $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]?)$/';
    if (!preg_match($ipv4_pattern, $ip) && !Requests_IPv6::check_ipv6($ip)) {
        return false;
    }
    return $ip;
}

WordPress Version: 4.7

/**
 * Determines if an IP address is valid.
 *
 * Handles both IPv4 and IPv6 addresses.
 *
 * @since 4.7.0
 *
 * @param  string $ip IP address.
 * @return string|false The valid IP address, otherwise false.
 */
function rest_is_ip_address($ip)
{
    $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]?)$/';
    if (!preg_match($ipv4_pattern, $ip) && !Requests_IPv6::check_ipv6($ip)) {
        return false;
    }
    return $ip;
}