Skip to content

fix for missing metadata in cropped image #68

Description

@fine-G

in the cropped image the description, caption and alt metadata ist lost.

find

 // Get the filetype
                $wp_filetype = wp_check_filetype(basename($targetFilePath), null );
                $attachment = array(

before this get the date as vars:

$originalFileObject = get_post($id);
$originalFileDescription = $originalFileObject->post_content;
$originalFileCaption = $originalFileObject->post_excerpt;
$originalFileAlt = $originalFileObject->_wp_attachment_image_alt;

the change the array:

$attachment = array(
                     'guid' => $mediaDir['url'] . '/' . basename($targetFilePath),
                     'post_mime_type' => $wp_filetype['type'],
                     'post_title' => preg_replace('/\.[^.]+$/', '', basename($targetFilePath)),
                     'post_content' => $originalFileDescription, // new!
                     'post_excerpt' => $originalFileCaption,	// new!
                     'post_status' => 'inherit'
                );

and after this add the alt to the new file:
update_post_meta( $attachmentId, '_wp_attachment_image_alt', $originalFileAlt );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions