I was uploading some images as part of a gallery field. During the upload there was a server error and the image did not save correctly to the DB. However it did upload the image and create the thumbnails.
When I loaded the page in the browser, I got an error:
Here is the function where the error is occurring:
The problem is on line 40 we are assuming that $attachment->ID will always exist in $metaDataValues array, which in my case was not true. A simple array_key_exists() check is therefore necessary:
foreach ($attachments as $attachment) {
if (array_key_exists($attachment->ID, $metaDataValues)) {
$image = new Image($this->post);
$image->fillFields($attachment);
$image->fillMetadataFields($metaDataValues[$attachment->ID]);
$this->images[] = $image;
}
}
Please let me know if you will add this in or if you want me to send a PR.
I was uploading some images as part of a gallery field. During the upload there was a server error and the image did not save correctly to the DB. However it did upload the image and create the thumbnails.
When I loaded the page in the browser, I got an error:
Here is the function where the error is occurring:
The problem is on line 40 we are assuming that
$attachment->ID
will always exist in$metaDataValues
array, which in my case was not true. A simplearray_key_exists()
check is therefore necessary:Please let me know if you will add this in or if you want me to send a PR.