| @@ -3,8 +3,10 @@ | ||
| 3 | 3 | namespace Extendify\Agent; |
| 4 | 4 | |
| 5 | 5 | defined('ABSPATH') || die('No direct access.'); |
| 6 | 6 | |
| 7 | +use Extendify\Shared\Services\Import\ImageUploader; | |
| 8 | + | |
| 7 | 9 | /** |
| 8 | 10 | * Adds an `images` field to WooCommerce's product abilities, which ship with no |
| 9 | 11 | * way to set a product image at all. |
| 10 | 12 | */ |
| @@ -176,17 +178,11 @@ | ||
| 176 | 178 | if (!\current_user_can('upload_files')) { |
| 177 | 179 | return false; |
| 178 | 180 | } |
| 179 | 181 | |
| 180 | - if (!function_exists('\media_sideload_image')) { | |
| 181 | - require_once ABSPATH . 'wp-admin/includes/media.php'; | |
| 182 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 183 | - require_once ABSPATH . 'wp-admin/includes/image.php'; | |
| 184 | - } | |
| 182 | + $uploaded = (new ImageUploader())->uploadImage($url); | |
| 185 | 183 | |
| 186 | - $id = \media_sideload_image($url, 0, null, 'id'); | |
| 187 | - | |
| 188 | - return \is_wp_error($id) ? false : $id; | |
| 184 | + return \is_wp_error($uploaded) ? false : $uploaded['attachment_id']; | |
| 189 | 185 | } |
| 190 | 186 | |
| 191 | 187 | private static function inputSchema() |
| 192 | 188 | { |