ACF\AI\Abilities
FieldGroup::get_location_schema
Returns the schema needed to create field group location rules.
Method of the class: FieldGroup{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->get_location_schema(): array;
Changelog
| Since 6.8.0 | Introduced. |
FieldGroup::get_location_schema() FieldGroup::get location schema code ACF 6.8.8
private function get_location_schema(): array {
// Get all location types organized by category
$location_types = acf_get_location_rule_types();
// Build oneOf schemas for each location type
$location_rule_schemas = array();
foreach ( $location_types as $types ) {
foreach ( $types as $param => $label ) {
// Create a sample rule to get operators and values
$sample_rule = array( 'param' => $param );
// Get operators for this param
$operators = acf_get_location_rule_operators( $sample_rule );
// Build schema for this specific location type
$location_rule_schemas[] = array(
'type' => 'object',
'properties' => array(
'param' => array(
'type' => 'string',
'enum' => array( $param ),
'description' => $label,
),
'operator' => array(
'type' => 'string',
'enum' => array_keys( $operators ),
'description' => 'Comparison operator',
'default' => '==',
),
'value' => array(
'type' => 'string',
'description' => sprintf( 'Value for %s', $label ),
),
),
'required' => array( 'param', 'operator', 'value' ),
);
}
}
// Return full location schema supporting multiple groups and rules
return array(
'type' => 'array',
'description' => 'Location rules determining where this field group appears. Each array item is an OR group containing AND rules.',
'minItems' => 1,
'items' => array(
'type' => 'array',
'description' => 'Group of location rules (AND logic)',
'minItems' => 1,
'items' => array(
'oneOf' => $location_rule_schemas,
),
),
);
}