<?php
/**
* REST API Fields
*/
class RestFields {
/**
* Construct
*/
public function __construct() {
// REST API fields
add_action( 'rest_api_init', array( $this, 'register_rest_fields' ) );
}
/**
* Register rest fields
*/
public function register_rest_fields() {
register_rest_field(
'download',
'download_fields',
array(
'get_callback' => array( $this, 'get_download_fields' ),
)
);
}
/**
* Download fields
*
* @return array Download fields
*/
public function get_download_fields( $object, $field_name, $request ) {
$id = $object['id'];
$values = array(
'download_category' => get_field( 'download_category', $object['id'] ),
'download_file_url' => get_field( 'download_file_url', $object['id'] ),
);
return $values;
}
}