Make WordPress Core

Opened 9 years ago

Last modified 6 years ago

#35648 new defect (bug)

the_post_thumbnail sets srcset with http protocol

Reported by: javiertoledos's profile javiertoledos Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: reporter-feedback https bulk-reopened
Focuses: Cc:

Description

We have a wordpress site that uses https always, when we use the_post_thumbnail, it returns HTTPS for the SRC attribute but it returns HTTP values for the SRCSET attribute. This is not a duplicate of #28261 or #15928 because this only happens on the srcset attribute.

We had to do this filter in order to do a quick patch:

<?php
function fix_srcset_https_thumb_images ($html) {
    
    if ( is_ssl()) {
        $html = str_replace('http://','https://',$html);
    }
    return $html;
}

add_filter('post_thumbnail_html','fix_srcset_https_thumb_images') ;

Attachments (1)

wordpress-bug.png (27.2 KB) - added by javiertoledos 9 years ago.
Screenshot of the SRC HTTP bug

Download all attachments as: .zip

Change History (8)

@javiertoledos
9 years ago

Screenshot of the SRC HTTP bug

#1 @dd32
9 years ago

@javiertoledos Can you please let us know how you've forced the site to HTTPS only?

Are you using any SSL constants? Plugins? What's your WordPress URL / Site URL set to (Settings -> General)? Is the media URL set to anything under Settings -> Media?

#2 @dd32
9 years ago

  • Component changed from Post Thumbnails to Media
  • Focuses ui javascript administration removed
  • Version changed from 4.4.1 to 4.4

#3 @johnbillion
9 years ago

  • Focuses template removed
  • Keywords reporter-feedback added

#4 @johnbillion
9 years ago

Related/dupe: #34945

#5 @johnbillion
9 years ago

  • Keywords https added

#6 @joshringer
9 years ago

Following the code trail: For src, comes from wp_get_attachment_image_src <- image_downsize <- wp_get_attachment_url where the url is fixed using set_url_scheme. This doesn't happen for srcset, which pulls its base url straight from _wp_upload_dir_baseurl.
Presumably, this could be fixed just after this point (search for $image_baseurl in wp_calculate_image_srcset), in a similar manner. Might be worth investigating putting it lower down in the root wp_upload_dir, though?

#9 @MikeHarris
6 years ago

  • Keywords bulk-reopened added

Its still relevant - I can replicate on Wordpress 5.1.1

Note: See TracTickets for help on using tickets.