Resolves the identity used to match a list member against another.
Description
The identity is simply the member’s value cast to a string, regardless of which key carries it: a bare scalar is its own identity, and a map is identified by the value of the first of the well-known identity keys (id, slug, field) it carries. Because the key is not part of the identity, a bare field like 'f3' matches any map carrying that value, whether it appears as array( 'id' => 'f3' ), array( 'slug' => 'f3' ), and so on — this lets the same shorthand target lists keyed by different fields. Casting to string keeps numeric identities matching whether they arrive as an int or a string. Anything else (e.g. a nested list) has no identity and never matches, so it is always appended.
Parameters
$itemmixedrequired- The list member.
Source
private function list_item_identity( $item ) {
if ( is_scalar( $item ) ) {
return (string) $item;
}
if ( is_array( $item ) && ! array_is_list( $item ) ) {
foreach ( array( 'id', 'slug', 'field' ) as $key ) {
if ( isset( $item[ $key ] ) && is_scalar( $item[ $key ] ) ) {
return (string) $item[ $key ];
}
}
}
return null;
}
Changelog
| Version | Description |
|---|---|
| 7.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.