wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_unique_id_from_values › WordPress Function
Since6.8.0
Deprecatedn/a
› wp_unique_id_from_values ( $data, $prefix = '' )
Parameters: (2) |
|
Returns: |
|
Defined at: |
|
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.Related Functions: wp_unique_term_slug, wp_unique_id, wp_unique_post_slug, wp_unique_filename, wp_unique_prefixed_id
Source
function wp_unique_id_from_values( array $data, string $prefix = '' ): string { if ( empty( $data ) ) { _doing_it_wrong( __FUNCTION__, sprintf( __( 'The $data argument must not be empty.' ), gettype( $data ) ), '6.8.0' ); } $serialized = wp_json_encode( $data ); $hash = substr( md5( $serialized ), 0, 8 ); return $prefix . $hash; }