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.
8175functionwp_unique_prefixed_id($prefix=''){8176static$id_counters=array();81778178if(!is_string($prefix)){8179wp_trigger_error(8180__FUNCTION__,8181sprintf('The prefix must be a string. "%s" data type given.',gettype($prefix))8182);8183$prefix='';8184}81858186if(!isset($id_counters[$prefix])){8187$id_counters[$prefix]=0;8188}81898190$id=++$id_counters[$prefix];81918192return$prefix.(string)$id;8193}
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 7.1.0 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.