Skip to content

Commit

Permalink
fix: lazyload replacement when image source is in data-src attributes…
Browse files Browse the repository at this point in the history
…, solving conflict with some gallery plugins
  • Loading branch information
selul committed Feb 12, 2019
1 parent bea5ac8 commit c26cdab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/lazyload_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function lazyload_tag_replace( $new_tag, $original_url, $new_url, $optml_
$new_tag = str_replace(
[
$original_url,
'src=',
' src=',
'srcset=', // Not ideal to disable srcset, we should aim to remove the srcset completely from code.
],
[
Expand Down
14 changes: 14 additions & 0 deletions tests/test-lazyload.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ public function test_check_with_no_script() {
$this->assertEquals( 1, substr_count( $replaced_content, '<noscript>' ) );
$this->assertEquals( 2, substr_count( $replaced_content, 'i.optimole.com' ) );
}


public function test_replacement_with_data_attr() {
$content = '<div class="before-footer">
<div class="codeinwp-container">
<p class="featuredon">Featured On</p>
<img src="http://www.example.org/wp-content/uploads/2018/05/brands.png" data-src="http://www.example.org/wp-content/uploads/2018/05/brands.png">
</div>
</div>';

$replaced_content = Optml_Manager::instance()->replace_content( $content );
$this->assertEquals( 5, substr_count( $replaced_content, 'i.optimole.com' ) );
$this->assertEquals( 1, substr_count( $replaced_content, 'data-opt-src' ) );
}
public function test_check_no_script() {
$replaced_content = Optml_Manager::instance()->process_images_from_content( self::HTML_TAGS_HEADER );

Expand Down

0 comments on commit c26cdab

Please sign in to comment.