
适合初学者和专业人士CSS备忘单
rest_is_field_included ( $field, $fields )
rest_is_field_included: 这是一个WordPress的函数,用来检查一个字段是否包含在REST API响应的字段集合中: 该函数接收一个字段名和一个字段数组,如果该字段被包括,则返回真,否则返回假: 这个函数被用来过滤REST API响应中返回的字段。
给出一个要包含在响应中的字段数组,其中一些可能是`嵌套.字段’,确定所提供的字段是否应该包含在响应体中。
如果一个父字段被传入,在该父字段中存在任何嵌套字段将导致该方法返回”true”。例如”title”,如果提供了任何一个`title`,`title.raw`或`title.rendered`,将返回true。
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; }