Yoast\WP\SEO\Generators
Schema_Generator::validate_type() private Yoast 1.0
Validates a graph piece's type.
When the type is an array:
- Ensure the values are unique.
- Only 1 value? Use that value without the array wrapping.
{} Это метод класса: Schema_Generator{}
Хуков нет.
Возвращает
Массив. The graph piece.
Использование
// private - только в коде основоного (родительского) класса $result = $this->validate_type( $piece );
- $piece(массив) (обязательный)
- The graph piece.
Код Schema_Generator::validate_type() Schema Generator::validate type Yoast 15.7
private function validate_type( $piece ) {
if ( ! isset( $piece['@type'] ) ) {
// No type to validate.
return $piece;
}
// If it is not an array, we can return immediately.
if ( ! \is_array( $piece['@type'] ) ) {
return $piece;
}
/*
* Ensure the types are unique.
* Use array_values to reset the indices (e.g. no 0, 2 because 1 was a duplicate).
*/
$piece['@type'] = \array_values( \array_unique( $piece['@type'] ) );
// Use the first value if there is only 1 type.
if ( \count( $piece['@type'] ) === 1 ) {
$piece['@type'] = \reset( $piece['@type'] );
}
return $piece;
}