Created
February 2, 2016 19:44
-
-
Save jwenerd/e81616c1dc87a4d145a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* The new responsive image feature in wordpress 4.4 causes image sourceset attribuet | |
to insert images as HTTP rather than HTTPS. This completely breaks images on sites where | |
the site is loaded ( and in sometimes force-loaded) to be served via HTTPS | |
The following plugin changes these images to be HTTPS if the site is served via HTTPS | |
*/ | |
if ( is_ssl() ) { | |
add_filter('wp_calculate_image_srcset', 'psu_https_srcset_fix' , 100 , 5); | |
} | |
function psu_https_srcset_fix( $sources, $size_array, $image_src, $image_meta, $attachment_id ){ | |
$http_site_url = get_site_url( get_current_blog_id(), '/', 'http' ); | |
$https_site_url = get_site_url( get_current_blog_id(), '/', 'https' ); | |
foreach( $sources as &$source ) { | |
if (strpos($source['url'], $http_site_url) !== false ){ | |
$source['url'] = str_replace($http_site_url, $https_site_url, $source['url'] ); | |
} | |
} | |
return $sources; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment