wp_is_uuid() WordPress Function

The wp_is_uuid() function checks whether a given string is a valid UUID. A UUID (Universal Unique Identifier) is a 32-character string that is used to identify a resource. UUIDs are typically used to identify items in a database, such as records or files. The wp_is_uuid() function can be used to check if a given string is a valid UUID. This can be useful when working with data that is stored in a UUID format.

wp_is_uuid( mixed $uuid, int $version = null ) #

Validates that a UUID is valid.


Parameters

$uuid

(mixed)(Required)UUID to check.

$version

(int)(Optional)Specify which version of UUID to check against. Default is none, to accept any UUID version. Otherwise, only version allowed is 4.

Default value: null


Top ↑

Return

(bool) The string is a valid UUID or false on failure.


Top ↑

Source

File: wp-includes/functions.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 );
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.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
Show More