WC_REST_CRUD_Controller::fetch_fields_using_getters()publicWC 1.0

Get fields for an object if getter is defined.

Method of the class: WC_REST_CRUD_Controller{}

No Hooks.

Return

Array. Data fetched from getters.

Usage

$WC_REST_CRUD_Controller = new WC_REST_CRUD_Controller();
$WC_REST_CRUD_Controller->fetch_fields_using_getters( $object, $context, $fields );
$object(object) (required)
Object we are fetching response for.
$context(string) (required)
Context of the request. Can be view or edit.
$fields(array) (required)
List of fields to fetch.

WC_REST_CRUD_Controller::fetch_fields_using_getters() code WC 8.6.1

public function fetch_fields_using_getters( $object, $context, $fields ) {
	$data = array();
	foreach ( $fields as $field ) {
		if ( method_exists( $this, "api_get_$field" ) ) {
			$data[ $field ] = $this->{"api_get_$field"}( $object, $context );
		}
	}
	return $data;
}