add_filter('stec_ics_import_post_data', function ($post_data, $item) { $attachment = isset($item->attach) ? $item->attach : null; $support = array('jpeg', 'png'); $ext = pathinfo($attachment, PATHINFO_EXTENSION); if ($attachment && in_array($ext, $support)) { require_once(ABSPATH . 'wp-admin/includes/file.php'); $tmp_file = download_url($attachment); if (is_wp_error($tmp_file)) { return $post_data; } $attachments_ids = \Stachethemes\Stec\Helpers::upload_images(array( array( 'name' => basename($attachment), 'tmp_name' => $tmp_file, 'type' => 'image/' . $ext ) )); $result = array(); if (is_array($attachments_ids) && $attachments_ids) { $result = array_map(function ($id) { $sizes = array('full', 'large', 'medium', 'thumbnail'); $result = array( 'id' => $id, 'sizes' => array(), 'dimensions' => array(), 'order' => 0 ); foreach ($sizes as $size) { $attachment = wp_get_attachment_image_src($id, $size); $result['sizes'][$size] = $attachment[0]; $result['dimensions'][$size] = array( 'width' => $attachment[1], 'height' => $attachment[2], 'ar' => $attachment[1] / $attachment[2] ); } return $result; }, $attachments_ids); $post_data['meta']['images'] = $result; } } return $post_data; }, 10, 2);