wp_is_uuid() – Validates that a UUID is valid.

You appear to be a bot. Output may be restricted

Description

Validates that a UUID is valid.

Usage

$bool = wp_is_uuid( $uuid, $version );

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`.

Returns

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

Source

File name: wordpress/wp-includes/functions.php
Lines:

1 to 18 of 18
function wp_is_uuid( $uuid, $version = null ) {

  if ( ! is_string( $uuid ) ) {
    return false;
  }

  if ( is_numeric( $version ) ) {
    if ( 4 !== (int) $version ) {
      _doing_it_wrong( wp_is_uuid, __( '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 );
}
 

 View on GitHub View on Trac