WP_View_Config_Data::list_item_identity │ private │ WP 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.

Метод класса: WP_View_Config_Data{}

Хуков нет.

Возвращает

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

Использование

// private - только в коде основоного (родительского) класса
$result = $this->list_item_identity( $item );
$item(разное) (обязательный)
The list member.

Список изменений

С версии 7.1.0 Введена.

Код WP_View_Config_Data::list_item_identity() WP 7.1.3

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