Changeset 60038 for trunk/src/wp-includes/functions.php
- Timestamp:
- 03/18/2025 12:41:31 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r59946 r60038 9175 9175 return hash_equals( $hash, wp_fast_hash( $message ) ); 9176 9176 } 9177 9178 /** 9179 * Generates a unique ID based on the structure and values of a given array. 9180 * 9181 * This function serializes the array into a JSON string and generates a hash 9182 * that serves as a unique identifier. Optionally, a prefix can be added to 9183 * the generated ID for context or categorization. 9184 * 9185 * @since 6.8.0 9186 * 9187 * @param array $data The input array to generate an ID from. 9188 * @param string $prefix Optional. A prefix to prepend to the generated ID. Default ''. 9189 * 9190 * @return string The generated unique ID for the array. 9191 */ 9192 function wp_unique_id_from_values( array $data, string $prefix = '' ): string { 9193 if ( empty( $data ) ) { 9194 _doing_it_wrong( 9195 __FUNCTION__, 9196 sprintf( 9197 __( 'The $data argument must not be empty.' ), 9198 gettype( $data ) 9199 ), 9200 '6.8.0' 9201 ); 9202 } 9203 $serialized = wp_json_encode( $data ); 9204 $hash = substr( md5( $serialized ), 0, 8 ); 9205 return $prefix . $hash; 9206 }
Note: See TracChangeset
for help on using the changeset viewer.