rest_is_ip_address() - WordPress 函数参考中文文档

返回介绍

rest_is_ip_address()

发布于 2017-09-11 字数1507 浏览 733 评论 0

rest_is_ip_address( string $ip )

Determines if an IP address is valid.


描述

Handles both IPv4 and IPv6 addresses.


参数

$ip

(string)
(Required)
IP address.


返回值

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


源代码

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

更新日志

Version 描述
4.7.0 Introduced.

相关函数

Uses

  • wp-includes/Requests/IPv6.php:
    Requests_IPv6::check_ipv6()

Used By

  • wp-includes/rest-api.php:
    rest_validate_value_from_schema()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::prepare_item_for_database()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!