WordPress at a glance

wp_is_uuid() WP 1.0

Validates that a UUID is valid.

✈ 1 time = 0.000104s = fast | 50000 times = 0.02s = speed of light | PHP 7.1.5, WP 4.9.4

No Hooks.

Return

true/false. The string is a valid UUID or false on failure.

Usage

wp_is_uuid( $uuid, $version );
$uuid(mixed) (required)
UUID to check.
$version(int)
Specify which version of UUID to check against. Otherwise, only version allowed is 4.
Default: none, to accept any UUID version

Code of wp_is_uuid: wp-includes/functions.php VER 5.0.1

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

Related Functions

From category: Helper Functions

No comments
    Hello, !     Log In . Register