WC_REST_Order_Refunds_Controller::get_preview_fields_for_response
Get the preview fields a request asks for, mirroring core's get_fields_for_response() against the preview schema instead of the controller's item schema.
Method of the class: WC_REST_Order_Refunds_Controller{}
No Hooks.
Returns
string[].
Usage
// private - for code of main (parent) class only $result = $this->get_preview_fields_for_response( $request ): array;
- $request(WP_REST_Request) (required)
- The request.
WC_REST_Order_Refunds_Controller::get_preview_fields_for_response() WC REST Order Refunds Controller::get preview fields for response code WC 11.1.2
private function get_preview_fields_for_response( $request ): array {
$schema = $this->get_public_preview_schema();
$properties = isset( $schema['properties'] ) && is_array( $schema['properties'] ) ? $schema['properties'] : array();
// For back-compat, include any registered field with an empty schema, as
// core's get_fields_for_response() does: without a schema the field never
// reaches the published properties, but its callback must still run.
foreach ( $this->get_additional_fields( 'order_refund_preview' ) as $field_name => $field_options ) {
if ( is_null( $field_options['schema'] ) ) {
$properties[ $field_name ] = $field_options;
}
}
$fields = array_map( 'strval', array_keys( $properties ) );
if ( ! isset( $request['_fields'] ) || empty( $request['_fields'] ) ) {
return $fields;
}
$requested_fields = array_map(
static function ( $field ): string {
return trim( (string) $field );
},
wp_parse_list( $request['_fields'] )
);
if ( 0 === count( $requested_fields ) ) {
return $fields;
}
return array_values(
array_filter(
$fields,
function ( string $field ) use ( $requested_fields ): bool {
return rest_is_field_included( $field, $requested_fields );
}
)
);
}