Automattic\WooCommerce\Blocks\AIContent
UpdateProducts::product_image_upload
Upload the image for the product.
Метод класса: UpdateProducts{}
Хуков нет.
Возвращает
int|Строку|WP_Error.
Использование
// private - только в коде основоного (родительского) класса $result = $this->product_image_upload( $product_id, $image_src, $image_alt );
- $product_id(int) (обязательный)
- The product ID.
- $image_src(строка) (обязательный)
- The image source.
- $image_alt(строка) (обязательный)
- The image alt.
Код UpdateProducts::product_image_upload() UpdateProducts::product image upload WC 10.4.3
private function product_image_upload( $product_id, $image_src, $image_alt ) {
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
// Since the media_sideload_image function is expensive and can take longer to complete
// the process of downloading the external image and uploading it to the media library,
// here we are increasing the time limit to avoid any issues.
set_time_limit( 150 );
wp_raise_memory_limit( 'image' );
return media_sideload_image( $image_src, $product_id, $image_alt, 'id' );
}