ACF_Rest_Api::get_field_groups_by_id()privateACF 1.0

Get all field groups for a given object.

Метод класса: ACF_Rest_Api{}

Хуков нет.

Возвращает

Массив. An array of matching field groups.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_field_groups_by_id( $object_id, $object_type, $object_sub_type, $scope );
$object_id(int) (обязательный)
-
$object_type(строка) (обязательный)
'user', 'term', or 'post'
$object_sub_type(строка|null)
The post type or taxonomy. When an $object_type of 'user' is in play, this can be ignored.
По умолчанию: null
$scope(массив)
Field group keys to limit the returned set of field groups to. This is used to scope field lookups to specific groups.
По умолчанию: array()

Код ACF_Rest_Api::get_field_groups_by_id() ACF 6.0.4

private function get_field_groups_by_id( $object_id, $object_type, $object_sub_type = null, $scope = array() ) {
	// When dealing with a term, we need the taxonomy in order to look up the relevant field groups. The taxonomy is expected
	// in the $object_sub_type variable but when building our schema, this isn't readily available. This block ensures the
	// taxonomy is set when not passed in.
	if ( $object_type === 'term' && $object_sub_type === null ) {
		$term = get_term( $object_id );
		if ( ! $term instanceof WP_Term ) {
			return array();
		}
		$object_sub_type = $term->taxonomy;
	}

	switch ( $object_type ) {
		case 'user':
			$args = array(
				'user_id'   => $object_id,
				'rest'      => true,
			);
			break;
		case 'term':
			$args = array( 'taxonomy' => $object_sub_type );
			break;
		case 'comment':
			$comment   = get_comment( $object_id );
			$post_type = get_post_type( $comment->comment_post_ID );
			$args      = array( 'comment'  => $post_type );
			break;
		case 'post':
		default:
			$args            = array( 'post_id' => $object_id );
			$child_rest_base = $this->request->get_url_param( 'child_rest_base' );
			if ( $child_rest_base && 'post' === $object_type ) {
				$args['post_type'] = $object_sub_type;
			}
	}

	// Only return field groups that are configured to show in REST.
	return array_filter(
		acf_get_field_groups( $args ),
		function ( $group ) use ( $scope ) {
			if ( $scope and ! in_array( $group['key'], $scope ) ) {
				return false;
			}

			return $group['show_in_rest'];
		}
	);
}