Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for missing metadata in cropped image #68

Open
fine-G opened this issue Feb 25, 2019 · 0 comments
Open

fix for missing metadata in cropped image #68

fine-G opened this issue Feb 25, 2019 · 0 comments

Comments

@fine-G
Copy link

fine-G commented Feb 25, 2019

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 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant