ACF_Rest_Api::maybe_apply_per_object_schema
Upgrade both OPTIONS surfaces (schema.properties.acf and endpoints[].args.acf) from the type-level union to per-object precision when the caller can read the target object.
Метод класса: ACF_Rest_Api{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->maybe_apply_per_object_schema();
Список изменений
| С версии 6.8.10 | Введена. |
Код ACF_Rest_Api::maybe_apply_per_object_schema() ACF Rest Api::maybe apply per object schema ACF 6.8.11
private function maybe_apply_per_object_schema() {
// Both outputs are only read during OPTIONS response building.
if ( ! ( $this->wp_request instanceof WP_REST_Request ) || 'OPTIONS' !== $this->wp_request->get_method() ) {
return;
}
if ( ! $this->request instanceof ACF_Rest_Request || ! $this->request->object_type ) {
return;
}
$child_id = $this->request->get_url_param( 'child_id' );
$object_id = $child_id ? $child_id : $this->request->get_url_param( 'id' );
// Collection routes are already correct at the type-level union.
if ( ! $object_id ) {
return;
}
if ( ! $this->current_user_can_read_request_object( $object_id, $child_id ) ) {
return;
}
$per_object = $this->build_per_object_schema( $object_id );
if ( empty( $per_object['properties'] ) ) {
return;
}
$this->per_object_schema = $per_object;
$base = $this->request->child_object_type
? $this->request->child_object_type
: $this->request->object_sub_type;
if ( ! $base ) {
return;
}
global $wp_rest_additional_fields;
if ( isset( $wp_rest_additional_fields[ $base ]['acf'] ) ) {
$wp_rest_additional_fields[ $base ]['acf']['schema'] = $per_object;
}
}