0

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.

1 Answer 1

3

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

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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