Skip to content

Gallery field "undefined offset" error #51

@omzy

Description

@omzy

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:

image

Here is the function where the error is occurring:

image

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.

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