/**
- Override the response object
@param
\WP_REST_Response $response
*
@param
\WP_Post $post
*
@param
\WP_REST_Request $request
*
*
@return
mixed
*/
public
function
overrideResponse
( $response, $post, $request )
{
if
( $post->post_type ===
'chapter'
) {
// Add rest link to associated part
$response->add_link(
'part'
, trailingslashit( rest_url( sprintf(
'%s/%s'
,
$this
->namespace,
'parts'
) ) ) . $post->post_parent
);
}
if
( in_array( $post->post_type, [
'front-matter'
,
'chapter'
,
'back-matter'
],
true
) ) {
// Add rest link to metadata
$response->add_link(
'metadata'
, trailingslashit( rest_url( sprintf(
'%s/%s/%d/metadata'
,
$this
->namespace,
$this
->rest_base, $post->ID ) ) )
);
}