From fca82f9a73e5f2b62155a86f1ade9de82b603dfd Mon Sep 17 00:00:00 2001 From: desrosj Date: Sun, 6 Jan 2019 20:08:45 +0000 Subject: [PATCH] General: Introduce `wp_unique_id()`, a PHP implementation of Underscore's `uniqueId` method. A static variable contains an integer that is incremented with each call. This number is returned with the optional prefix. As such the returned value is not universally unique, but it is unique across the life of the PHP process. Props westonruter, dlh. Merges [43658] and [44406] to the 5.0 branch. See #44883. Built from https://develop.svn.wordpress.org/branches/5.0@44407 git-svn-id: http://core.svn.wordpress.org/branches/5.0@44237 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 20 ++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index d4af13f2a8..53d0073ab5 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -5793,6 +5793,26 @@ function wp_is_uuid( $uuid, $version = null ) { return (bool) preg_match( $regex, $uuid ); } +/** + * Get unique ID. + * + * This is a PHP implementation of Underscore's uniqueId method. A static variable + * contains an integer that is incremented with each call. This number is returned + * with the optional prefix. As such the returned value is not universally unique, + * but it is unique across the life of the PHP process. + * + * @since 5.0.3 + * + * @staticvar int $id_counter + * + * @param string $prefix Prefix for the returned ID. + * @return string Unique ID. + */ +function wp_unique_id( $prefix = '' ) { + static $id_counter = 0; + return $prefix . (string) ++$id_counter; +} + /** * Get last changed date for the specified cache group. * diff --git a/wp-includes/version.php b/wp-includes/version.php index e303a62f04..ae405e1157 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0.3-alpha-44405'; +$wp_version = '5.0.3-alpha-44407'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.