@@ -8029,6 +8029,38 @@ function wp_unique_prefixed_id( $prefix = '' ) {
80298029 return $ prefix . (string ) $ id ;
80308030}
80318031
8032+ /**
8033+ * Generates a unique ID based on the structure and values of a given array.
8034+ *
8035+ * This function serializes the array into a JSON string and generates a hash
8036+ * that serves as a unique identifier. Optionally, a prefix can be added to
8037+ * the generated ID for context or categorization.
8038+ *
8039+ * @since 6.8.0
8040+ *
8041+ * @param array $data The input array to generate an ID from.
8042+ * @param string $prefix Optional. A prefix to prepend to the generated ID. Default empty string.
8043+ * @return string The generated unique ID for the array.
8044+ */
8045+ function wp_unique_id_from_values ( array $ data , string $ prefix = '' ): string {
8046+ if ( empty ( $ data ) ) {
8047+ _doing_it_wrong (
8048+ __FUNCTION__ ,
8049+ sprintf (
8050+ /* translators: %s: The parameter name. */
8051+ __ ( 'The %s parameter must not be empty. ' ),
8052+ '$data '
8053+ ),
8054+ '6.8.0 '
8055+ );
8056+ }
8057+
8058+ $ serialized = wp_json_encode ( $ data );
8059+ $ hash = substr ( md5 ( $ serialized ), 0 , 8 );
8060+
8061+ return $ prefix . $ hash ;
8062+ }
8063+
80328064/**
80338065 * Gets last changed date for the specified cache group.
80348066 *
@@ -9173,34 +9205,3 @@ function wp_verify_fast_hash(
91739205
91749206 return hash_equals ( $ hash , wp_fast_hash ( $ message ) );
91759207}
9176-
9177- /**
9178- * Generates a unique ID based on the structure and values of a given array.
9179- *
9180- * This function serializes the array into a JSON string and generates a hash
9181- * that serves as a unique identifier. Optionally, a prefix can be added to
9182- * the generated ID for context or categorization.
9183- *
9184- * @since 6.8.0
9185- *
9186- * @param array $data The input array to generate an ID from.
9187- * @param string $prefix Optional. A prefix to prepend to the generated ID. Default ''.
9188- *
9189- * @return string The generated unique ID for the array.
9190- */
9191- function wp_unique_id_from_values ( array $ data , string $ prefix = '' ): string {
9192- if ( empty ( $ data ) ) {
9193- _doing_it_wrong (
9194- __FUNCTION__ ,
9195- sprintf (
9196- /* translators: %s: parameter name. */
9197- __ ( 'The %s argument must not be empty. ' ),
9198- '$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- }
0 commit comments