$uploadInfo['url'] . '/' . $imageName . '.' . $ext,
'path' => $target,
'name' => $imageName
);
$resizingEnabled = false;
$compressionEnabled = false;
// for the function wp_generate_attachment_metadata() to work
require_once(ABSPATH . 'wp-admin/includes/image.php');
foreach( $media as $key => $item ) {
$attachment = array(
'guid' => $item['guid'],
'post_mime_type' => $mime,
'post_title' => $item['name'],
'post_name' => $item['name'],
'post_content' => '',
'post_status' => 'inherit',
);
$media[$key]['id'] = wp_insert_attachment( $attachment, $item['path'], $parentId );
$attach_data = wp_generate_attachment_metadata( $media[$key]['id'], $item['path'] );
wp_update_attachment_metadata( $media[$key]['id'], $attach_data );
}
$id = $media['base']['id'];
$cssClasses = ' ' . trim( get_option( 'imgevr_css_class', '' ) );
if ( !empty( $id ) ) {
$html = "
";
} else {
$html = "
";
}
$linksEnabled = get_option( 'imgevr_links_enable', false );
if ( $linksEnabled ) {
$saveOriginal = get_option('imgevr_resizing_save_original', false);
if ( $resizingEnabled && $saveOriginal ) {
$html = "" . $html . '';
} else {
$html = "" . $html . '';
}
}
$result = array(
'html' => $html
);
echo json_encode($result);
exit;
}
add_action('wp_ajax_imageinsert_upload', 'imgevr_upload_image');