wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_unique_prefixed_id › WordPress Function

Depuis6.4.0
Dépréciéen/a
wp_unique_prefixed_id ( $prefix = '' )
Paramètres:
  • (string) $prefix Optional. Prefix for the returned ID. Default empty string.
    Requis: Non
    Défaut: (vide)
Retourne:
  • (string) Incremental ID per prefix.
Défini(e) dans:
Codex:

Generates an incremental ID that is independent per each different prefix.

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.


Source

function wp_unique_prefixed_id( $prefix = '' ) {
	static $id_counters = array();

	if ( ! is_string( $prefix ) ) {
		wp_trigger_error(
			__FUNCTION__,
			sprintf( 'The prefix must be a string. "%s" data type given.', gettype( $prefix ) )
		);
		$prefix = '';
	}

	if ( ! isset( $id_counters[ $prefix ] ) ) {
		$id_counters[ $prefix ] = 0;
	}

	$id = ++$id_counters[ $prefix ];

	return $prefix . (string) $id;
}