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.
8013functionwp_unique_prefixed_id($prefix=''){8014static$id_counters=array();80158016if(!is_string($prefix)){8017wp_trigger_error(8018__FUNCTION__,8019sprintf('The prefix must be a string. "%s" data type given.',gettype($prefix))8020);8021$prefix='';8022}80238024if(!isset($id_counters[$prefix])){8025$id_counters[$prefix]=0;8026}80278028$id=++$id_counters[$prefix];80298030return$prefix.(string)$id;8031}
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.8.8 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.