rest_is_field_included()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
rest_is_field_included( string $field, array $fields ): bool
Описание
Если передано родительское поле, наличие любого вложенного поля внутри него заставит метод вернуть true. Например, «title» вернёт true, если указано любое из title, title.raw или title.rendered.
Оригинал (английский)
If a parent field is passed in, the presence of any nested field within that parent will cause the method to return true. For example “title” will return true if any of title, title.raw or title.rendered is provided.
Параметры
$field
string
обязательный
$fields
array
обязательный
Возвращаемое значение
bool
Исходный код
wp-includes/rest-api.php:996
function rest_is_field_included( $field, $fields ) {
if ( in_array( $field, $fields, true ) ) {
return true;
}
foreach ( $fields as $accepted_field ) {
/*
* Check to see if $field is the parent of any item in $fields.
* A field "parent" should be accepted if "parent.child" is accepted.
*/
if ( str_starts_with( $accepted_field, "$field." ) ) {
return true;
}
/*
* Conversely, if "parent" is accepted, all "parent.child" fields
* should also be accepted.
*/
if ( str_starts_with( $field, "$accepted_field." ) ) {
return true;
}
}
return false;
}
История изменений
| Версия | Описание |
|---|---|
| 5.3.0 | Introduced. |

