public function buildListOfKnownMedia( $url ) {
		// Handle request (local or global)
		$params = [
			'per_page' => 100,
		];
		$response = $this->handleGetRequest( $url, 'wp/v2', 'media', $params );

		// Handle errors
		if ( is_wp_error( $response ) ) {
			$_SESSION['pb_errors'][] = sprintf(
				'<p>%1$s</p><p>%2$s</p>',
				__( 'The source book&rsquo;s media could not be read.', 'pressbooks' ),
				$response->get_error_message()
			);
			return false;
		}

		$known_media = [];
		foreach ( $response as $item ) {
			$m = $this->createMediaEntity( $item );
			if ( $item['media_type'] === 'image' ) {
				foreach ( $item['media_details']['sizes'] as $size => $info ) {
					$attached_file = image_strip_baseurl( $info['source_url'] ); // 2017/08/foo-bar-300x225.png
					$known_media[ $attached_file ] = $m;
				}
			} else {
				$attached_file = media_strip_baseurl( $m->sourceUrl ); // 2017/08/foo-bar.ext
				$known_media[ $attached_file ] = $m;
			}
		}

		return $known_media;
	}
public function buildListOfKnownMedia( $url ) {
		// Handle request (local or global)
		$params = [
			'per_page' => 100,
		];
		$response = $this->handleGetRequest( $url, 'wp/v2', 'media', $params );

		// Handle errors
		if ( is_wp_error( $response ) ) {
			$_SESSION['pb_errors'][] = sprintf(
				'<p>%1$s</p><p>%2$s</p>',
				__( 'The source book&rsquo;s media could not be read.', 'pressbooks' ),
				$response->get_error_message()
			);
			return false;
		}

		$known_media = [];
		foreach ( $response as $item ) {
			$m = $this->createMediaEntity( $item );
			if ( $item['media_type'] === 'image' ) {
				foreach ( $item['media_details']['sizes'] as $size => $info ) {
					$attached_file = image_strip_baseurl( $info['source_url'] ); // 2017/08/foo-bar-300x225.png
					$known_media[ $attached_file ] = $m;
				}
			} else {
				$attached_file = media_strip_baseurl( $m->sourceUrl ); // 2017/08/foo-bar.ext
				$known_media[ $attached_file ] = $m;
			}
		}

		return $known_media;
	}
public function buildListOfKnownMedia ( $ url ) { // Handle request (local or global) $ params = [ 'per_page' => 100 , ] ; $ response = $ this -> handleGetRequest ( $ url , 'wp/v2' , 'media' , $ params ) ; // Handle errors if ( is_wp_error ( $ response ) ) { $ _SESSION [ 'pb_errors' ] [ ] = sprintf ( '<p>%1$s</p><p>%2$s</p>' , __ ( 'The source book&rsquo;s media could not be read.' , 'pressbooks' ) , $ response -> get_error_message ( ) ) ; return false ; } $ known_media = [ ] ; foreach ( $ response as $ item ) { $ m = $ this -> createMediaEntity ( $ item ) ; if ( $ item [ 'media_type' ] === 'image' ) { foreach ( $ item [ 'media_details' ] [ 'sizes' ] as $ size => $ info ) { $ attached_file = image_strip_baseurl ( $ info [ 'source_url' ] ) ; // 2017/08/foo-bar-300x225.png $ known_media [ $ attached_file ] = $ m ; } } else { $ attached_file = media_strip_baseurl ( $ m -> sourceUrl ) ; // 2017/08/foo-bar.ext $ known_media [ $ attached_file ] = $ m ; } } return $ known_media ; }
Use media endpoint to build an array of known media

@param string $url The URL of the book.

@return bool|\Pressbooks\Entities\Cloner\Media[] False if the operation failed; known images assoc array if succeeded.
Use media endpoint to build an array of known media