Our site uses TLS and to the best of my ability I've forced TLS everywhere. I've defined FORCE_SSL_ADMIN to be true and also tried the following filter which I've borrowed from the plugin SSL Insecure Content FIxer (https://wordpress.org/plugins/ssl-insecure-content-fixer/):

function fix_ssl_attachment_url( $url ) {
  if ( is_ssl() ) {
    if (stripos($url, 'http://') === 0) {
        $url = 'https' . substr($url, 4);
    }
  }
  return $url;
}
add_filter( 'wp_get_attachment_url', 'fix_ssl_attachment_url', 9999 );


Despite the above, for whatever reason the Featured Image metabox is attempting to load thumbnails via HTTP, causing it to fail to load and no preview to be displayed. Interestingly, the media library itself seems to be behaving correctly. The front end of the site has no issues. Here's a screenshot of the area I'm talking about, since I'm pretty sure I got some of the terminology wrong:


Broken thumbnail


Installation of the above-mentioned plugin seems to actually solve the issue, but I can't figure out why and I'm not big on leaving plugins installed that I really shouldn't need. The site has been on HTTPS for a while and I think the issue only began recently, leading me to believe it's something I screwed up but I can't for the life of me figure out what that may have been.

It turned out to be a problem with the uploads directory (not sure what caused it initially). I was able to resolve the issue with the following filter:

function fix_ssl( $url ) {
    if ( is_ssl() ) {
        if (stripos($url, 'http://') === 0) {
        $url = 'https' . substr($url, 4);
        }
    }
    return $url;
}

function uploadDir($uploads) {
    $uploads['url'] = fix_ssl($uploads['url']);
    $uploads['baseurl'] = fix_ssl($uploads['baseurl']);
    return $uploads;
}

add_filter('upload_dir', 'uploadDir');

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.