ACF_Rest_Api::object_type_has_field_group()
Gets an array of the location types that a field group is configured to use.
Метод класса: ACF_Rest_Api{}
Хуков нет.
Возвращает
true|false
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->object_type_has_field_group( $object_type, $field_group, $location_types );
- $object_type(строка) (обязательный)
- 'user', 'term', or 'post'
- $field_group(массив) (обязательный)
- The field group to check.
- $location_types(массив)
- An array of location types.
По умолчанию: array()
Код ACF_Rest_Api::object_type_has_field_group() ACF Rest Api::object type has field group ACF 6.0.4
private function object_type_has_field_group( $object_type, $field_group, $location_types = array() ) { if ( ! isset( $field_group['location'] ) || ! is_array( $field_group['location'] ) ) { return false; } $location_types = empty( $location_types ) ? acf_get_location_types() : $location_types; foreach ( $field_group['location'] as $rule_group ) { $match = false; foreach ( $rule_group as $rule ) { $rule = acf_validate_location_rule( $rule ); if ( ! isset( $location_types[ $rule['param'] ] ) ) { continue; } // Make sure the main object type matches. $location_type = $location_types[ $rule['param'] ]; if ( ! isset( $location_type->object_type ) || $location_type->object_type !== (string) $object_type ) { continue; } /** * For posts/pages, we can only be sure that fields will show up if * the field group is configured to show up for all items of the current * post type. */ if ( 'post' === $object_type && 'post_type' === $rule['param'] ) { if ( $rule['operator'] === '==' && $this->request->object_sub_type !== $rule['value'] ) { continue; } if ( $rule['operator'] === '!=' && $this->request->object_sub_type === $rule['value'] ) { continue; } $match = true; } if ( 'term' === $object_type && 'taxonomy' === $rule['param'] ) { if ( $rule['operator'] === '==' && $this->request->object_sub_type !== $rule['value'] ) { continue; } if ( $rule['operator'] === '!=' && $this->request->object_sub_type === $rule['value'] ) { continue; } $match = true; } if ( in_array( $object_type, array( 'user', 'comment' ) ) ) { $match = true; } } if ( $match ) { return true; } } return false; }