Skip to content

Missing thumbnails for private attachments in Media library #631

@mklasen

Description

@mklasen

Heya!

I noticed private attachment thumbnails are not showing when the Media library is shown in (default) grid view. I've solved this on my own environment with the following snippet;

add_filter( 'wp_prepare_attachment_for_js', array( $this, 'prepare_js_attachments' ) );

	public function prepare_js_attachments( $attachment ) {
		$s3_uploads = \S3_Uploads\Plugin::get_instance();
		if ( $s3_uploads->is_private_attachment( $attachment['id'] ) ) {
			if ( isset( $attachment['sizes'] ) && is_array( $attachment['sizes'] ) ) {
				foreach ( $attachment['sizes'] as &$size ) {
					$size['url'] = $s3_uploads->add_s3_signed_params_to_attachment_url( $size['url'], $attachment['id'] );
				}
			}
		}
		return $attachment;
	}

Happy to provide a PR :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions