Advertisement
jdgrimes

BJ Lazy Load Bug Patch

Jun 14th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1.             /*
  2.              * We start out with $imgHTML_raw, instead of $imgHTML.
  3.              */
  4.             foreach ( $matches[0] as $imgHTML_raw ) {
  5.  
  6.                 /*
  7.                  * Replace the current site URL with the network URL.
  8.                  */
  9.                 $imgHTML = str_replace( get_site_url(), network_site_url(), $imgHTML_raw );
  10.                
  11.                 // don't to the replacement if a skip class is provided and the image has the class
  12.                 if ( ! ( is_array( $this->_skip_classes ) && preg_match( $skip_images_regex, $imgHTML_raw ) ) ) {
  13.                     // replace the src and add the data-src attribute
  14.                     $replaceHTML = preg_replace( '/<img(.*?)src=/i', '<img$1src="' . $this->_placeholder_url . '" data-lazy-type="image" data-lazy-src=', $imgHTML );
  15.  
  16.                     // add the lazy class to the img element
  17.                     if ( preg_match( '/class="/i', $replaceHTML ) ) {
  18.                         $replaceHTML = preg_replace( '/class="(.*?)"/i', 'class="lazy lazy-hidden $1"', $replaceHTML );
  19.                     } else {
  20.                         $replaceHTML = preg_replace( '/<img/i', '<img class="lazy lazy-hidden"', $replaceHTML );
  21.                     }
  22.  
  23.                     $replaceHTML .= '<noscript>' . $imgHTML_raw . '</noscript>';
  24.  
  25.                     array_push( $search, $imgHTML_raw );
  26.                     array_push( $replace, $replaceHTML );
  27.                 }
  28.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement