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 );
in the cropped image the description, caption and alt metadata ist lost.
find
before this get the date as vars:
the change the array:
and after this add the alt to the new file:
update_post_meta( $attachmentId, '_wp_attachment_image_alt', $originalFileAlt );