wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes
rest_is_field_included › WordPress Function
Depuis5.3.0
Dépréciéen/a
› rest_is_field_included ( $field, $fields )
| Paramètres: (2) |
|
| Retourne: |
|
| Défini(e) dans: |
|
| Codex: |
Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body.
If a parent field is passed in, the presence of any nested field within that parent will cause the method to returntrue. For example "title"
will return true if any of title, title.raw or title.rendered is
provided.Fonctions en relation: rest_is_ip_address, rest_api_loaded, rest_is_integer, tinymce_include, rest_stabilize_value
Source
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;
}