jchristopher / attachments

[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
wordpress.org/extend/plugins/attachments/
GNU General Public License v2.0
241 stars 78 forks source link

File size shows 0kB over SSL #155

Closed nerdcowuk closed 6 years ago

nerdcowuk commented 8 years ago

Hi,

I found, what I believe to be, a bug within a plugin. Don't think it's a biggie, but here it is:

I am hosting a website with WP Engine. The website was non-SSL for a while, but I purchased SSL certificate at some point. When you request SSL certificate with them, they don't do search & replace on database for http:// and replace it with https://. They seem to force it (somehow) during the processing, so options in database keep using "http://".

Keeping this in mind, when your plugin tries to perform the following lines

classes/class.attachments.php:496-498

$url        = is_string( $size ) ? $this->src( $size, $index ) : wp_get_attachment_url( $this->attachments[ $index ]->id ); // produces "https://"
$uploads    = wp_upload_dir(); // consists of "http://" as per database
$file_path  = str_replace( $uploads['baseurl'], $uploads['basedir'], $url ); // fails

it fails to generate an absolute path for the desired file. This is because the wp_upload_dir() works off database options, which is non-ssl, and the $url variable holds SSL permalink. Therefore the str_replace fails to find "http://" in the $url variable and replace it with an absolute path.

I patched it with a simple line $url = str_replace( "https://", http://", $url ); but ideally it would be good to have any kind of a versatile fix released (or at least a hook / filter added, so I can modify it on-fly).

I hope this all makes sense. If not, feel free to ask for further details.

Thanks a lot!

jchristopher commented 6 years ago

Hello, given the age of this Issue I'm going to mark it as Closed but if this is still a problem please comment here!