protected function renderBook( $id, $search = null ) {

		switch_to_blog( $id );

		// Search
		if ( ! empty( $search ) ) {
			if ( ! $this->find( $search ) ) {
				restore_current_blog();
				return [];
			}
		}

		$request_metadata = new \WP_REST_Request( 'GET', '/pressbooks/v2/metadata' );
		$response_metadata = rest_do_request( $request_metadata );

		$request_toc = new \WP_REST_Request( 'GET', '/pressbooks/v2/toc' );
		$response_toc = rest_do_request( $request_toc );

		$item = [
			'id' => $id,
			'link' => get_blogaddress_by_id( $id ),
			'metadata' => $this->prepare_response_for_collection( $response_metadata ),
			'toc' => $this->prepare_response_for_collection( $response_toc ),
		];

		$this->linkCollector['api'][] = [
			'href' => get_rest_url( $id ),
		];

		restore_current_blog();

		$this->linkCollector['metadata'][] = [
			'href' => $item['metadata']['_links']['self'][0]['href'],
		];
		unset( $item['metadata']['_links'] );

		$this->linkCollector['toc'][] = [
			'href' => $item['toc']['_links']['self'][0]['href'],
		];
		foreach ( $item['toc']['_links']['metadata'] as $v ) {
			$this->linkCollector['metadata'][] = [
				'href' => $v['href'],
			];
		}
		unset( $item['toc']['_links'] );

		$this->linkCollector['self'][] = [
			'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ),
		];

		return $item;
	}
protected function renderBook( $id, $search = null ) {

		switch_to_blog( $id );

		// Search
		if ( ! empty( $search ) ) {
			if ( ! $this->find( $search ) ) {
				restore_current_blog();
				return [];
			}
		}

		$request_metadata = new \WP_REST_Request( 'GET', '/pressbooks/v2/metadata' );
		$response_metadata = rest_do_request( $request_metadata );

		$request_toc = new \WP_REST_Request( 'GET', '/pressbooks/v2/toc' );
		$response_toc = rest_do_request( $request_toc );

		$item = [
			'id' => $id,
			'link' => get_blogaddress_by_id( $id ),
			'metadata' => $this->prepare_response_for_collection( $response_metadata ),
			'toc' => $this->prepare_response_for_collection( $response_toc ),
		];

		$this->linkCollector['api'][] = [
			'href' => get_rest_url( $id ),
		];

		restore_current_blog();

		$this->linkCollector['metadata'][] = [
			'href' => $item['metadata']['_links']['self'][0]['href'],
		];
		unset( $item['metadata']['_links'] );

		$this->linkCollector['toc'][] = [
			'href' => $item['toc']['_links']['self'][0]['href'],
		];
		foreach ( $item['toc']['_links']['metadata'] as $v ) {
			$this->linkCollector['metadata'][] = [
				'href' => $v['href'],
			];
		}
		unset( $item['toc']['_links'] );

		$this->linkCollector['self'][] = [
			'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ),
		];

		return $item;
	}
protected function renderBook ( $ id , $ search = null ) { switch_to_blog ( $ id ) ; // Search if ( ! empty ( $ search ) ) { if ( ! $ this -> find ( $ search ) ) { restore_current_blog ( ) ; return [ ] ; } } $ request_metadata = new \ WP_REST_Request ( 'GET' , '/pressbooks/v2/metadata' ) ; $ response_metadata = rest_do_request ( $ request_metadata ) ; $ request_toc = new \ WP_REST_Request ( 'GET' , '/pressbooks/v2/toc' ) ; $ response_toc = rest_do_request ( $ request_toc ) ; $ item = [ 'id' => $ id , 'link' => get_blogaddress_by_id ( $ id ) , 'metadata' => $ this -> prepare_response_for_collection ( $ response_metadata ) , 'toc' => $ this -> prepare_response_for_collection ( $ response_toc ) , ] ; $ this -> linkCollector [ 'api' ] [ ] = [ 'href' => get_rest_url ( $ id ) , ] ; restore_current_blog ( ) ; $ this -> linkCollector [ 'metadata' ] [ ] = [ 'href' => $ item [ 'metadata' ] [ '_links' ] [ 'self' ] [ 0 ] [ 'href' ] , ] ; unset ( $ item [ 'metadata' ] [ '_links' ] ) ; $ this -> linkCollector [ 'toc' ] [ ] = [ 'href' => $ item [ 'toc' ] [ '_links' ] [ 'self' ] [ 0 ] [ 'href' ] , ] ; foreach ( $ item [ 'toc' ] [ '_links' ] [ 'metadata' ] as $ v ) { $ this -> linkCollector [ 'metadata' ] [ ] = [ 'href' => $ v [ 'href' ] , ] ; } unset ( $ item [ 'toc' ] [ '_links' ] ) ; $ this -> linkCollector [ 'self' ] [ ] = [ 'href' => rest_url ( sprintf ( '%s/%s/%d' , $ this -> namespace , $ this -> rest_base , $ id ) ) , ] ; return $ item ; }
Switches to a book, renders it for use in JSON response if found

@param int $id
@param mixed $search (optional)

@return array
Switches to a book renders it for use in JSON response if found