Title: Duplicate code and a feature request
Last modified: March 29, 2018

---

# Duplicate code and a feature request

 *  Resolved [mackzwellz](https://wordpress.org/support/users/mackzwellz/)
 * (@mackzwellz)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/duplicate-code-and-a-feature-request/)
 * Trying to have my site not to serve mixed content under certain CDN provider’s
   Flexible SSL (successful result included in the code snippet below) I discovered
   that you seem to have a duplicated code in your plugin:
 *     ```
       ...
       // Remove sizes and srcset attribute.
       $img->removeAttribute( 'sizes' );
       $img->removeAttribute( 'srcset' );
   
       // TODO: add "} // End if()." and delete everything below until next TODO
       // Get src value.
       $src = $img->getAttribute( 'src' );
   
       // Check if we have a src.
       if ( '' === $src ) {
       // Set the value from data-noscript as src.
       $src = $img->getAttribute( 'data-noscript' );
       } // End if().
   
       // Set data-src value.
       $img->setAttribute( 'data-src', $src );
       } else {
       // TODO: Stop here
       // Get src attribute.
       $src = $img->getAttribute( 'src' );
       // TODO: Review new optional code: stripping HTTP and HTTPS from src URLs
       // or could you even maybe make it toggleable via checkbox in admin panel?
       $src = str_replace(['http:', 'https:'], '', $src);
   
       			// Check if we do not have a value.
       			if ( '' === $src ) {
       				// Set the value from data-noscript as src.
       				$src = $img->getAttribute( 'data-noscript' );
       			} // End if().
   
       			// Set data-src value.
       			$img->setAttribute( 'data-src', $src );
       // TODO: Delete the line below too.
       }// End if().
       ```
   
 * I would be happy to be proven wrong, but after my changes everything works as
   it did before, so consider it both a minor bug report and a minor feature request.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Florian Brinkmann](https://wordpress.org/support/users/florianbrinkmann/)
 * (@florianbrinkmann)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/duplicate-code-and-a-feature-request/#post-10133597)
 * Hi,
 * oh, you are right, the `else` is not necessary there, thanks! Changed that ([https://github.com/florianbrinkmann/lazy-loading-responsive-images/blob/master/src/Plugin.php](https://github.com/florianbrinkmann/lazy-loading-responsive-images/blob/master/src/Plugin.php)).
 * To the protocol thing: so you would like an option that removes the `http` or`
   https` from the image URL? Can you eplain what exactly is the problem that you
   have with the CDN providers?
 * Thanks,
    Florian
 *  Thread Starter [mackzwellz](https://wordpress.org/support/users/mackzwellz/)
 * (@mackzwellz)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/duplicate-code-and-a-feature-request/#post-10136620)
 * Well, in certain cirumstances (site with Cloudflare Flexible SSL + HTTPS Rewrites
   and no own server SSL)  data-src and <nosript> img src attribute URLs aren’t 
   replaced, and on image load page turns into mixed SSL.
    Oh, and reviewing the
   code a bit more, I came up with a better place to put this string:
 *     ```
       * Replace images with placeholders in the content
   
       ...
   
       // Strip protocol scheme from src and data-src
       $replace = str_replace(['http:', 'https:'], '', $replace);
   
       $content = str_replace( $search, $replace, $content );
       ```
   
 * I’d suggest making it a checkbox option, or let users even choose – strip both
   HTTP and HTTPS, replace HTTP with HTTPS or do nothing. Or maybe you could make
   the plugin choose automatically (i.e. check site adress protocol scheme in wp
   options) – and make it a fourth option! (alright, this might be a bit over the
   top). Either way, the [best practice right now is to always use HTTPS](https://stackoverflow.com/questions/28446314/why-use-protocol-relative-urls-at-all),
   but not everyone may be using it still obviously.
 *  Plugin Author [Florian Brinkmann](https://wordpress.org/support/users/florianbrinkmann/)
 * (@florianbrinkmann)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/duplicate-code-and-a-feature-request/#post-10137192)
 * Hey,
 * thanks for explanation and your code, I will think about the best way to implement
   that feature!
 * Best,
    Florian

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Duplicate code and a feature request’ is closed to new replies.

 * ![](https://ps.w.org/lazy-loading-responsive-images/assets/icon-256x256.png?rev
   =1305473)
 * [Lazy Loader](https://wordpress.org/plugins/lazy-loading-responsive-images/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/lazy-loading-responsive-images/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/lazy-loading-responsive-images/)
 * [Active Topics](https://wordpress.org/support/plugin/lazy-loading-responsive-images/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/lazy-loading-responsive-images/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/lazy-loading-responsive-images/reviews/)

## Tags

 * [minor bug](https://wordpress.org/support/topic-tag/minor-bug/)

 * 3 replies
 * 2 participants
 * Last reply from: [Florian Brinkmann](https://wordpress.org/support/users/florianbrinkmann/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/duplicate-code-and-a-feature-request/#post-10137192)
 * Status: resolved