wpseek.com
Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_unique_id_from_values › WordPress Function

Da6.8.0
Deprecaton/a
› wp_unique_id_from_values ( $data, $prefix = '' )
Parametri: (2)
  • (array) $data The input array to generate an ID from.
    Richiesto: Sì
  • (string) $prefix Optional. A prefix to prepend to the generated ID. Default empty string.
    Richiesto: No
    Default: (vuoto)
Ritorna:
  • (string) The generated unique ID for the array.
Definito a:
Codex:

Generates a unique ID based on the structure and values of a given array.

This function serializes the array into a JSON string and generates a hash that serves as a unique identifier. Optionally, a prefix can be added to the generated ID for context or categorization.


Sorgenti

function wp_unique_id_from_values( array $data, string $prefix = '' ): string {
	if ( empty( $data ) ) {
		_doing_it_wrong(
			__FUNCTION__,
			sprintf(
				/* translators: %s: The parameter name. */
				__( 'The %s parameter must not be empty.' ),
				'$data'
			),
			'6.8.0'
		);
	}

	$serialized = wp_json_encode( $data );
	$hash       = substr( md5( $serialized ), 0, 8 );

	return $prefix . $hash;
}