Tự động download ảnh từ website khác.

Đầu tiên các bạn tạo 1 file.php tên là allProductImages.php với các tham số là tên của ảnh cần download

allProductImages.php
return [
"ajax-loader.gif",
"arrow_right.png",
"author.jpg",
"banner.jpg",
];

Sau đó copy đoạn code dưới và cho vào functions.php. Nhớ tạo folder store-images trong public_html hoặc các bạn có thể lưu ở chỗ nào mình thích và sửa đường link cần lưu là được chỗ $put_link ý

$baselink: Folder chứa ảnh cần lấy

functions.php
// Curl can be used but needs some processing to get the images names in an array.
// $data = wp_remote_get('https://e-web.vn/wp-content/themes/tsst/images/');
// $body = wp_remote_retrieve_body($data);
$allProductImages = include "allProductImages.php";
$baselink = 'https://e-web.vn/wp-content/themes/tsst/images/';
foreach ($allProductImages as $img_slug) {
$image_file = file_get_contents($baselink . $img_slug);
$put_link = $_SERVER['DOCUMENT_ROOT'].'/store-images/'.$img_slug;
file_put_contents($put_link, $image_file);
}