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', 'glossary' ], 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 ) ) ) );
		}

		// Check that we are in view/embed context (and)
		// Check that content is password protected (and)
		// Check that content is empty (if not then API has already verified that the user can_access_password_content)
		if ( in_array( $request['context'], [ 'view', 'embed' ], true ) ) {
			if ( ! empty( $response->data['content'] ) ) {
				if ( $response->data['content']['protected'] && empty( $response->data['content']['rendered'] ) ) {
					// Hide raw data
					$response->data['content']['raw'] = '';
				}
			}
			if ( ! empty( $response->data['excerpt'] ) ) {
				if ( $response->data['excerpt']['protected'] && empty( $response->data['excerpt']['rendered'] ) ) {
					// Hide raw data
					$response->data['excerpt']['raw'] = '';
				}
			}
		}

		return $response;
	}
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', 'glossary' ], 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 ) ) ) );
		}

		// Check that we are in view/embed context (and)
		// Check that content is password protected (and)
		// Check that content is empty (if not then API has already verified that the user can_access_password_content)
		if ( in_array( $request['context'], [ 'view', 'embed' ], true ) ) {
			if ( ! empty( $response->data['content'] ) ) {
				if ( $response->data['content']['protected'] && empty( $response->data['content']['rendered'] ) ) {
					// Hide raw data
					$response->data['content']['raw'] = '';
				}
			}
			if ( ! empty( $response->data['excerpt'] ) ) {
				if ( $response->data['excerpt']['protected'] && empty( $response->data['excerpt']['rendered'] ) ) {
					// Hide raw data
					$response->data['excerpt']['raw'] = '';
				}
			}
		}

		return $response;
	}
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' , 'glossary' ] , 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 ) ) ) ) ; } // Check that we are in view/embed context (and) // Check that content is password protected (and) // Check that content is empty (if not then API has already verified that the user can_access_password_content) if ( in_array ( $ request [ 'context' ] , [ 'view' , 'embed' ] , true ) ) { if ( ! empty ( $ response -> data [ 'content' ] ) ) { if ( $ response -> data [ 'content' ] [ 'protected' ] && empty ( $ response -> data [ 'content' ] [ 'rendered' ] ) ) { // Hide raw data $ response -> data [ 'content' ] [ 'raw' ] = '' ; } } if ( ! empty ( $ response -> data [ 'excerpt' ] ) ) { if ( $ response -> data [ 'excerpt' ] [ 'protected' ] && empty ( $ response -> data [ 'excerpt' ] [ 'rendered' ] ) ) { // Hide raw data $ response -> data [ 'excerpt' ] [ 'raw' ] = '' ; } } } return $ response ; }
Override the response object

@param \WP_REST_Response $response
@param \WP_Post $post
@param \WP_REST_Request $request

@return mixed
Override the response object