I am using latest WordPress and want to paste some post to my blog.
The "Auto Upload Images" plugin is the perfect one to download images automatically from remote.
But, it doesn’t work anymore after downloading from WordPress center.
The plugin Github page was updated since 2 years ago. There are lots of people met same issue and no one solve.
So I downloaded the latest and spent 1 day to debug it with PHP 8.1 and XDebug extension.
Reason
The reason why it does’t work is because it was unable to download images from remote.
Auto Upload Images uses WordPress wp_remote_get()
to download remote images in downloadImage($url) {}
function.
However, it always got this error:
cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0
Which means it occurs issues to download the images.
Solution
I tried to add 'sslverify' => false
to wp_remote_get()
but still got error.
The right way to solve it is to add User-Agent
to the header.
- Open file
src/ImageUploader.php
with any text editor. - Navigate to line
186
. - Add value to
user-agent
,$args
will become:$args = [ 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36', ];
- Done.