ACF\Pro\Datastore
Revisions::canonicalize_acf_value
Recursively sorts associative array keys for canonical JSON encoding.
Sequential arrays (repeater rows, flexible content layouts, multi-value selections) keep their user-defined order; associative arrays -- at any level, regardless of whether keys are ACF field keys, the acf_fc_layout discriminator, or other string keys (e.g. link field title/url/target) -- are sorted by key. JSON object keys are semantically unordered, so this is a no-op for consumers but makes the stored bytes byte-stable across saves so WordPress's revision meta byte comparison treats reordered saves as equal.
Method of the class: Revisions{}
No Hooks.
Returns
Mixed.
Usage
$result = Revisions::canonicalize_acf_value( $value );
- $value(mixed) (required)
- Decoded JSON value.
Changelog
| Since 6.8.1 | Introduced. |
Revisions::canonicalize_acf_value() Revisions::canonicalize acf value code ACF 6.8.8
private static function canonicalize_acf_value( $value ) {
if ( ! is_array( $value ) || array() === $value ) {
return $value;
}
$is_sequential = array_keys( $value ) === range( 0, count( $value ) - 1 );
if ( ! $is_sequential ) {
ksort( $value );
}
foreach ( $value as $k => $v ) {
$value[ $k ] = self::canonicalize_acf_value( $v );
}
return $value;
}