rest_is_field_included
函数
rest_is_field_included ( $field, $fields )
- 参数
-
-
(string)
$field
A field to test for inclusion in the response body.- Required: 是
-
(array)
$fields
An array of string fields supported by the endpoint.- Required: 是
-
(string)
- 返回值
-
- (bool) Whether to include the field or not.
- 定义位置
-
-
wp-includes/rest-api.php
, line 934
-
wp-includes/rest-api.php
- 引入
- 5.3.0
- 弃用
- –
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 return `true`. For example “title”
will return true if any of `title`, `title.raw` or `title.rendered` is
provided.
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 ( strpos( $accepted_field, "$field." ) === 0 ) { return true; } // Conversely, if "parent" is accepted, all "parent.child" fields // should also be accepted. if ( strpos( $field, "$accepted_field." ) === 0 ) { return true; } } return false; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。