ACF\AI\GEO

Schema::get_valid_output_formatspublic staticACF 6.8.0

Get valid output formats for a field/property combination

When a field type supports multiple output formats (e.g., image can output URL or ImageObject), this returns the formats valid for a specific property.

Method of the class: Schema{}

No Hooks.

Returns

Array. Array of valid output format types

Usage

$result = Schema::get_valid_output_formats( $field_type, $property );
$field_type(string) (required)
The ACF field type name.
$property(string) (required)
The Schema.org property name.

Changelog

Since 6.8.0 Introduced.

Schema::get_valid_output_formats() code ACF 6.8.8

public static function get_valid_output_formats( $field_type, $property ) {
	$field_ranges    = self::get_field_type_ranges( $field_type );
	$property_ranges = self::get_property_range( $property );

	if ( empty( $field_ranges ) || empty( $property_ranges ) ) {
		return array();
	}

	$valid_formats = array();

	foreach ( $field_ranges as $field_range ) {
		// Direct match
		if ( in_array( $field_range, $property_ranges, true ) ) {
			$valid_formats[] = $field_range;
			continue;
		}

		// Skip inheritance check for primitive types.
		if ( in_array( $field_range, self::$primitive_types, true ) ) {
			continue;
		}

		// Check if field range is a subtype of any property range
		foreach ( $property_ranges as $property_range ) {
			// Skip if property expects a primitive type.
			if ( in_array( $property_range, self::$primitive_types, true ) ) {
				continue;
			}

			if ( self::is_parent_of( $property_range, $field_range ) ) {
				$valid_formats[] = $field_range;
				break;
			}
		}

		// For fields that output Thing, include property ranges and their subtypes.
		// This allows Group/Repeater fields to show specific types like Person, HowToStep.
		if ( 'Thing' === $field_range ) {
			foreach ( $property_ranges as $property_range ) {
				// Skip primitives.
				if ( in_array( $property_range, self::$primitive_types, true ) ) {
					continue;
				}

				// Include the property range itself if it's a structural subtype of Thing.
				if ( self::is_parent_of( $field_range, $property_range ) ) {
					if ( self::type_has_properties( $property_range ) ) {
						$valid_formats[] = $property_range;
					}
				}

				// Also include subtypes of the property range (e.g., HowToStep for CreativeWork).
				$type_hierarchy = SchemaData::get_type_hierarchy();
				foreach ( $type_hierarchy as $type => $parent ) {
					if ( self::is_parent_of( $property_range, $type ) ) {
						if ( self::type_has_properties( $type ) ) {
							$valid_formats[] = $type;
						}
					}
				}
			}
		}
	}

	// Handle text value types (Duration, Distance, etc.).
	// These are modeled as objects in Schema.org but are really formatted strings.
	// Text fields should be able to output these types.
	if ( in_array( 'Text', $field_ranges, true ) ) {
		foreach ( $property_ranges as $property_range ) {
			if ( in_array( $property_range, self::$text_value_types, true ) ) {
				$valid_formats[] = $property_range;
			}
		}
	}

	return array_unique( $valid_formats );
}