• I upgraded my blog to WordPress 4.4 today and a whole lot of images showed up as broken. I tracked it down to the ‘srcset’ attribute on img tags not being populated correctly. The Azure plugin basically adjusts the url for images to point it at the blob store. That adjustment works for ‘src’ but with the new reactive design stuff on ‘srcset’, those adjustments don’t get called.

    This needs to get fixed as part of the plugin but, in the meantime, I implemented a pretty kludgy workaround to get back up and running again.

    You can fix it by editing the ‘windows-azure-storage.php’ file and the following lines:

    add_filter(
        'wp_calculate_image_srcset',
        'windows_azure_storage_wp_calculate_image_srcset',
        9,
        5
    );
    
    function windows_azure_storage_wp_calculate_image_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id )
    {
       	$searchString = "www.benday.com/wp-content/uploads/D:homesitewwwroot/wp-content/uploads";
    
       	$replaceString = "bendayblog.blob.core.windows.net/wp-public";
       	$valueAfterReplacement = "";
    
       	foreach ( $sources as &$source ) {
    		$valueAfterReplacement = str_replace($searchString, $replaceString, $source['url']);
       		$source['url'] = $valueAfterReplacement;
    	}
    
        return $sources;
    }

    You’ll need to replace the $searchString and $replaceString values with the appropriate strings for your blog and azure account.

    Hope this helps.

    -Ben
    [Signature moderated]

    https://wordpress.org/plugins/windows-azure-storage/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thanks for the quick fix!
    And I’m glad Google found this post right away πŸ˜‰

    Thanks for this. Hopefully there is an official fix soon.

    Is there a known fix for the “unable to edit/crop” in the standard WordPress editor?

    Ignore my last, was missing php5-gd when moving from Web App to Azure VM πŸ™‚

    Thanks for pointing out the filter that needed to be looked at. We’ve prepared what we hope is a longer term fix. It’s already been tested on multisites as well.

    http://projectnami.org/fix-for-azure-storage-plugin-and-wp-4-4/

    Hi, what’s the issue has been fixed? I don’t understand this issue, so can you provide some repro steps to help me understand it?

    Featured images are having an SrcSet tag added to them. The plugin was not designed to update the image references in this tag, so the featured images are breaking.

    Apparently Internet Explorer may not support the SrcSet tag, as I was only able to repro in Chrome and Firefox.

    Thanks!

    When MS is going to upgrade this piece of crap 2 years old plugin!!! COMON!

    Sadly, this fix nor the latest 3.0 release (which appears to have a fix built-in), isn’t working for me. The srcset on some images are not being updated. Any suggestions?

    i want to revert back and put all the images on the server i am hosting at.
    any idea how to do this without breaking things?

    Is there any long-term fix for this issue?

    The one published in this thread and the one submitted in the link below didn’t help me to resolve it.

    http://projectnami.org/fix-for-azure-storage-plugin-and-wp-4-4/

    Every time I apply one of them, the site is broken and I get 500 error message in the front-end and back-end.

    Any help?

    I’m with jdixon04 — this fix nor the one in the latest release works.

    I’m going to spend some time messing with it right now, and see if I can work out a new fix, then post it back here. However, if someone has gotten this working and can save me the time, I’d appreciate it if you’d post it!

    OK, I figured out the issue occurring for me, probably for jdixon04 as well:

    In the windows-azure-storage.php file, scroll down to approx line 721, or search for:
    function windows_azure_storage_wp_calculate_image_srcset

    Look for the if statements comparing whether a substr of the $media_info[‘blob’] equals the filename.

    If you were to echo out that substr, e.g.
    echo substr( $media_info['blob'], strrpos( $media_info['blob'], '/' ) + 1 )

    You might find that the first letter of your image name is missing.

    Remove the +1 from the inside of the substr function IN THE IF STATEMENT (NOT OF THE $img_filename variable declaration!!!), at approx line 735 so that it then looks like this:
    if ( substr( $media_info['blob'], strrpos( $media_info['blob'], '/' ) ) === $img_filename ) {

    and approx line 739 so that it then looks like this:
    if ( substr( $thumbnail, strrpos( $thumbnail, '/' ) ) === $img_filename ) {

    And your issue will get fixed.

    It occurred to me that it may help to just see the final function fixed.

    here it is.

    function windows_azure_storage_wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
    	$media_info = get_post_meta( $attachment_id, 'windows_azure_storage_info', true );
    
    	// If a CNAME is configured, make sure only 'http' is used for the protocol.
    	$azure_cname       = WindowsAzureStorageUtil::getCNAME();
    	$esc_url_protocols = ! empty ( $azure_cname ) ? array( 'https', 'http', '//' ) : null;
    
    	if ( ! empty( $media_info ) ) {
    		$base_url = trailingslashit( WindowsAzureStorageUtil::get_storage_url_base( false ) .
    		                             $media_info['container'] );
    
    		foreach ( $sources as &$source ) {
    			$img_filename = substr( $source['url'], strrpos( $source['url'], '/' ) + 1 );
    
    			if ( substr( $media_info['blob'], strrpos( $media_info['blob'], '/' ) ) === $img_filename ) {
    				$source['url'] = esc_url( $base_url . $media_info['blob'], $esc_url_protocols );
    			} else {
    				foreach ( $media_info['thumbnails'] as $thumbnail ) {
    					if ( substr( $thumbnail, strrpos( $thumbnail, '/' ) ) === $img_filename ) {
    						$source['url'] = esc_url( $base_url . $thumbnail, $esc_url_protocols );
    						break;
    					}
    
    				}
    
    			}
    
    		}
    
    	}
    
    	return $sources;
    }

    Thread Starter benday

    (@benday)

    I liked being able to store my content in Azure but I get the feeling that this plugin isn’t being enthusiastically supported/maintained anymore.

    If anyone is looking for a guide for how to get *off* of the Azure Storage Plugin, SuperGraham has a great walkthrough on how to do it. https://wordpress.org/support/topic/decommission-windows-azure-storage-for-wordpress-plugin

    -Ben

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Image 'srcset' attribute not populated correctly in 4.4’ is closed to new replies.