WP_View_Config_Data::list_item_identityprivateWP 7.1.0

Resolves the identity used to match a list member against another.

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.

Method of the class: WP_View_Config_Data{}

No Hooks.

Returns

string|null. The identity, or null when the member has none.

Usage

// private - for code of main (parent) class only
$result = $this->list_item_identity( $item );
$item(mixed) (required)
The list member.

Changelog

Since 7.1.0 Introduced.

WP_View_Config_Data::list_item_identity() code WP 7.1

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;
}