WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#35966 closed defect (bug) (worksforme)

Problem reintroduced in 4.4 with responsive img srcset

Reported by: hopetommola Owned by: joemcgill
Milestone: Priority: normal
Severity: normal Version: 4.4.2
Component: Media Keywords: https
Focuses: multisite Cc:

Description

This is a follow-up to #14867.

Running multisite.

Since updating to 4.4.2, this problem has come back up. When an image is uploaded to the media library, the src and srcset URLs are all hardcoded to http:// rather than using the blog's address, which is https://

https://blogs.hope.edu/stories-of-hope/social-sciences/cfl-and-shi-partners-in-ideas-innovation-and-leadership/

Change History (9)

#1 @joemcgill
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the report @hopetommola.

I believe this is a duplicate of #34945. Feel free to track the progress of this issue there.

Joe

#2 @hopetommola
3 years ago

Thank you sir!

#3 @hopetommola
3 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Actually, having read through the ticket history a bit, I think it's a different situation. That guy's ticket is about changing the site url from http to https and really doing it improperly caused the issue. We have been https since install. See srcset image:

<img class="size-full wp-image-124 alignleft" src="https://blogs.hope.edu/alumni/wp-content/uploads/sites/39/2016/02/Anne.jpg" alt="Anne" width="4511" height="3598" srcset="http://blogs.hope.edu/alumni/wp-content/uploads/sites/39/2016/02/Anne-300x239.jpg 300w, http://blogs.hope.edu/alumni/wp-content/uploads/sites/39/2016/02/Anne-768x613.jpg 768w, http://blogs.hope.edu/alumni/wp-content/uploads/sites/39/2016/02/Anne-1024x817.jpg 1024w, http://blogs.hope.edu/alumni/wp-content/uploads/sites/39/2016/02/Anne.jpg 4511w" sizes="(max-width: 4511px) 100vw, 4511px">

Note that the original image src is https:// but the srcset images are all http://
This is pushing the mixed content from a warning to an error, and therefore not showing the image at all.

#4 @SergeyBiryukov
3 years ago

  • Milestone set to Awaiting Review

#5 @joemcgill
3 years ago

  • Component changed from Permalinks to Media
  • Keywords https added
  • Owner set to joemcgill
  • Status changed from reopened to reviewing

@hopetommola Can you tell me a bit more about your setup?

  • Is the site url saved in the database using an HTTPS scheme (e.g. get_option('siteurl'))?
  • Do you have any constants set for WP_SITEURL?
  • What is the value of baseurl coming from wp_upload_dir()?

It's possible for your site url to be outputting an HTTP scheme and still have image src attributes showing as HTTPS when viewing the site over HTTPS depending on whether wp_upload_dir() is outputting an HTTP scheme instead of HTTPS.

#6 @hopetommola
3 years ago

Sorry for the delay. The weekend started with travel back from a conference and ended with moving two houses into one.

Used:

<?php
$uploads = wp_upload_dir();
$uploads=implode("<br />",$uploads);
echo $uploads;
?>

I have temporarily added the following to my child theme's functions.php file to force https:

add_filter( 'wp_calculate_image_srcset', function( $sources )
{
    foreach( $sources as &$source )
    {
        if( isset( $source['url'] ) )
            $source['url'] = set_url_scheme( $source['url'], 'https' );
    }
    return $sources;

}, PHP_INT_MAX );

ht: http://wordpress.stackexchange.com/questions/211375/how-do-i-disable-responsive-images-in-wp-4-4

#7 @joemcgill
3 years ago

Thanks @hopetommola. I'm not able to reproduce this issue on a clean install of WP 4.4.2. It's definitely odd that wp_upload_dir() is returning an HTTPS scheme for the baseurl but you're seeing HTTP scheme srcset attributes. Is it possible that you have some other plugins or filters interfering?

Can you also see what _wp_upload_dir_baseurl() is returning?

Thanks,
Joe

#8 @hopetommola
3 years ago

Added the following to the same page used above after the horizontal rule

<?php
$baseurl = _wp_upload_dir_baseurl();
echo $baseurl;
?>

#9 @joemcgill
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from reviewing to closed

wp_calculate_image_srcset() uses _wp_upload_dir_baseurl() to build those srcset attributes in WP 4.4, so I'm unsure how the srcset attributes would be created using the wrong scheme unless there is something else interfering on your specific setup.

If you or someone else can show how this can be reproduced using a clean install of WP 4.4 without any plugins activated, we can look into again.

Note: See TracTickets for help on using tickets.