WordPress errors uploading images

WordPress errors uploading images

I recently encountered a problem with WordPress image uploads.

The following code was called to attach an uploaded image to a WordPress post and set it as the WordPress featured image, or post thumbnail as its called in the code..

[snippet slug=wordpress-image-upload-errror lang=abap]

The problem is that the code kept failing. We checked the logging of is_wp_error and found the following error:

[snippet slug=wordpress-is_wp_error lang=php]

Our site uses SSL (https://), however on the server itself we use a self signed certificate. The reason for this is because this site gets very busy during black friday and as such we’re running it on AWS ec2 containers, through an AWS load balancer and cloudflare in front of that.

Both the AWS load balancer and cloudflare have their own certificates. Over and above that, we need to be able to spin up servers from images in a minute or two during peak load times and we couldn’t possibly wait for SSL certificates on the server to be up and running, so built in self signed certificates just work for us on that side of the load balancers..

Locally, though, when wordpress does a cURL to get the image, it fails the certificate check because its doing a local lookup, its not going through cloudflare.

It turns out the solution is pretty simple. Simply tell wordpress to not verify certificates.

The following code can be put into your plugin file (as it was for us), or into the functions.php file for your theme:

[snippet slug=dont-verify-ssl lang=php]

As soon as we added the code above our images uploaded and were added as the post’s thumbnail as expected.


Leave a Reply

Your email address will not be published. Required fields are marked *