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.
8085functionwp_unique_prefixed_id($prefix=''){8086static$id_counters=array();80878088if(!is_string($prefix)){8089wp_trigger_error(8090__FUNCTION__,8091sprintf('The prefix must be a string. "%s" data type given.',gettype($prefix))8092);8093$prefix='';8094}80958096if(!isset($id_counters[$prefix])){8097$id_counters[$prefix]=0;8098}80998100$id=++$id_counters[$prefix];81018102return$prefix.(string)$id;8103}
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.0.4 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.