rest_is_ip_address() WordPress Function

This function checks if an IP address is in an IPv4 or IPv6 format.

rest_is_ip_address( string $ip ) #

Determines if an IP address is valid.


Description

Handles both IPv4 and IPv6 addresses.


Top ↑

Parameters

$ip

(string)(Required)IP address.


Top ↑

Return

(string|false) The valid IP address, otherwise false.


Top ↑

Source

File: wp-includes/rest-api.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More