验证UUID是否有效。
原型
wp_is_uuid( mixed $uuid, int $version = null )
参数
$uuid
(mixed)
(Required)
UUID要检查。
$version
(int)
(Optional)
指定要检查的UUID版本。默认为none,接受任何UUID版本。否则,只允许的版本是4。
返回值
(bool)
字符串是有效的UUID或失败时为false。
源文件
路径:wp-includes/functions.php
<?php
...
function wp_is_uuid( $uuid, $version = null ) {
if ( ! is_string( $uuid ) ) {
return false;
}
if ( is_numeric( $version ) ) {
if ( 4 !== (int) $version ) {
_doing_it_wrong( __FUNCTION__, __( 'Only UUID V4 is supported at this time.' ), '4.9.0' );
return false;
}
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
} else {
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
}
return (bool) preg_match( $regex, $uuid );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_is_uuid/