Skip to content

Commit

Permalink
Merge pull request #6 from humanmade/support-for-wp-5.8
Browse files Browse the repository at this point in the history
Add support for WordPress 5.8
  • Loading branch information
roborourke authored Sep 27, 2021
2 parents 45a83cc + 3300709 commit 95b1cac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
],
"require": {
"php": ">=7.2",
"humanmade/asset-manager-framework": "^0.12"
"humanmade/asset-manager-framework": "^0.13.0"
}
}
25 changes: 17 additions & 8 deletions inc/class-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AssetManagerFramework\Image;
use AssetManagerFramework\Interfaces\Resize;
use AssetManagerFramework\MediaList;
use AssetManagerFramework\MediaResponse;
use AssetManagerFramework\Provider as BaseProvider;
use stdClass;
use WP_Post;
Expand Down Expand Up @@ -74,9 +75,9 @@ protected function parse_args( array $input ) : array {
* Retrieve the images for a query.
*
* @param array $args Query args from the media library
* @return MediaList Found images.
* @return MediaResponse Found images.
*/
protected function request( array $args ) : MediaList {
protected function request( array $args ) : MediaResponse {
if ( ! empty( $args['s'] ) ) {
return $this->search_images( $args );
} else {
Expand All @@ -88,24 +89,28 @@ protected function request( array $args ) : MediaList {
* Retrieve the images for a list query.
*
* @param array $args Query args from the media library
* @return MediaList Found images.
* @return MediaResponse Found images.
*/
protected function request_images( array $args ) : MediaList {
protected function request_images( array $args ) : MediaResponse {
$query = $this->parse_args( $args );

$response = $this->fetch( '/photos', $query );
$items = $this->prepare_images( $response['data'] );

return new MediaList( ...$items );
return new MediaResponse(
new MediaList( ...$items ),
$response['headers']['x-total'],
$response['headers']['x-per-page']
);
}

/**
* Retrieve the images for a search query.
*
* @param array $args Query args from the media library
* @return MediaList Found images.
* @return MediaResponse Found images.
*/
protected function search_images( array $args ) : MediaList {
protected function search_images( array $args ) : MediaResponse {
$query = $this->parse_args( $args );

$response = $this->fetch( '/search/photos', $query );
Expand All @@ -128,7 +133,11 @@ protected function search_images( array $args ) : MediaList {
$items[] = $item;
}

return new MediaList( ...$items );
return new MediaResponse(
new MediaList( ...$items ),
$response['headers']['x-total'],
$response['headers']['x-per-page']
);
}

/**
Expand Down

0 comments on commit 95b1cac

Please sign in to comment.