On this page
wp_is_uuid( mixed $uuid, int $version = null ): bool
Validates that a UUID is valid.
Parameters
$uuidmixed Required-
UUID to check.
$versionint Optional-
Specify which version of UUID to check against. Default is none, to accept any UUID version. Otherwise, only version allowed is
4.Default:
null
Return
bool The string is a valid UUID or false on failure.
Source
File: wp-includes/functions.php. View all references
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
Uses
| Uses | Description |
|---|---|
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _doing_it_wrong() wp-includes/functions.php | Marks something as being incorrectly called. |
Used By
| Used By | Description |
|---|---|
| wp_is_authorize_application_password_request_valid() wp-admin/includes/user.php | Checks if the Authorize Application Password request is valid. |
| WP_Customize_Manager::establish_loaded_changeset() wp-includes/class-wp-customize-manager.php | Establishes the loaded changeset. |
| rest_validate_value_from_schema() wp-includes/rest-api.php | Validate a value based on a schema. |
| WP_Customize_Manager::setup_theme() wp-includes/class-wp-customize-manager.php | Starts preview and customize theme. |
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_is_uuid