Generates an incremental ID that is independent per each different prefix.
Description
It is similar to wp_unique_id, but each prefix has its own internal ID counter to make each prefix independent from each other. The ID starts at 1 and increments on each call. The returned value is not universally unique, but it is unique across the life of the PHP process and it's stable per prefix.
Parameters
$prefixstringoptional
Prefix for the returned ID. Default empty string.Default: ''
Return
string
Incremental ID per prefix.
Uses · 1
wp_trigger_error()Generates a user-level error/warning/notice/deprecation message.
7982functionwp_unique_prefixed_id($prefix=''){7983static$id_counters=array();79847985if(!is_string($prefix)){7986wp_trigger_error(7987__FUNCTION__,7988sprintf('The prefix must be a string. "%s" data type given.',gettype($prefix))7989);7990$prefix='';7991}79927993if(!isset($id_counters[$prefix])){7994$id_counters[$prefix]=0;7995}79967997$id=++$id_counters[$prefix];79987999return$prefix.(string)$id;8000}
History
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.