Skip to content

Commit

Permalink
fix: handle case when image doesn't have sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Apr 19, 2024
1 parent bdef3b7 commit bc2a0d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion alt-text-generator-gpt-vision.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: AI Alt Text Generator for GPT Vision
* Plugin URI: https://github.com/android-com-pl/wp-ai-alt-generator
* Description: Automatically generate alternative text for images using OpenAI's GPT Vision API.
* Version: 2.1.1
* Version: 2.1.3
* Requires at least: 6.3
* Requires PHP: 8.1
* Author: android.com.pl
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: alt text, accessibility, SEO, GPT-4, GPT-V, OpenAI
Requires at least: 6.3
Tested up to: 6.5
Requires PHP: 8.1
Stable tag: 2.1.1
Stable tag: 2.1.3
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Plugin URI: https://github.com/android-com-pl/wp-ai-alt-generator
Expand Down
6 changes: 5 additions & 1 deletion src/components/BulkGenerateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export default function BulkGenerateModal({
const thumbnail =
//@ts-ignore - missing WP types
attachment.media_details.sizes?.thumbnail ??
attachment.media_details.sizes?.[0];
attachment.media_details.sizes?.[0] ?? {
width: attachment.media_details.width,
height: attachment.media_details.height,
source_url: attachment.source_url,
};

if (thumbnail)
details.thumbnail = {
Expand Down
15 changes: 7 additions & 8 deletions src/hooks/useAttachments.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { type Attachment, useEntityRecords } from "@wordpress/core-data";

export default function useAttachments(ids: number[]) {
const { records, hasResolved } = useEntityRecords<Attachment<"view">>(
"postType",
"attachment",
{
include: ids,
per_page: -1,
},
);
const { records, hasResolved, isResolving } = useEntityRecords<
Attachment<"view">
>("postType", "attachment", {
include: ids,
per_page: -1,
context: "view",
});

return { attachments: records ?? [], hasResolved };
}

0 comments on commit bc2a0d9

Please sign in to comment.