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.
8033functionwp_unique_prefixed_id($prefix=''){8034static$id_counters=array();80358036if(!is_string($prefix)){8037wp_trigger_error(8038__FUNCTION__,8039sprintf('The prefix must be a string. "%s" data type given.',gettype($prefix))8040);8041$prefix='';8042}80438044if(!isset($id_counters[$prefix])){8045$id_counters[$prefix]=0;8046}80478048$id=++$id_counters[$prefix];80498050return$prefix.(string)$id;8051}
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.9.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.