Skip to content

Commit

Permalink
Merge pull request #81 from wp-media/branch-2.0.3
Browse files Browse the repository at this point in the history
2.0.3
  • Loading branch information
remyperona authored Jan 16, 2019
2 parents d43be7a + 92b1549 commit 43ffa19
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"require": {
"php": ">=5.4.0",
"league/container": "^2.4",
"wp-media/rocket-lazyload-common": "^1.0.0"
"wp-media/rocket-lazyload-common": "^2.0.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: lazyload, lazy load, images, iframes, thumbnail, thumbnails, smiley, smili
Requires at least: 4.7
Tested up to: 5.0.2
Requires PHP: 5.4
Stable tag: 2.0.2
Stable tag: 2.0.3

Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.

Expand Down Expand Up @@ -78,6 +78,12 @@ The element you want to apply lazyload on must have this specific markup:
The element must have the class `rocket-lazyload-bg`, and a `data-bg` attribute, which value is the CSS url for the image.

== Changelog ==
= 2.0.3 =
* Bugfix: Prevent incorrect display if JavaScript is disabled
* Bugfix: Don't apply lazyload on Divi/Extra/Beaver Builder Editor pages
* Bugfix: Use the correct URL for each iframe when multiple iframes are on the same page
* Bugfix: Ignore content inside inline script tags to prevent applying lazyload in it

= 2.0.2 =
* Bugfix: Fix an error in the compatibility for the AMP plugin

Expand Down
4 changes: 2 additions & 2 deletions rocket-lazy-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Lazy Load by WP Rocket
* Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
* Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
* Version: 2.0.2
* Version: 2.0.3
* Author: WP Media
* Author URI: https://wp-rocket.me
* Text Domain: rocket-lazy-load
Expand All @@ -27,7 +27,7 @@

defined('ABSPATH') || die('Cheatin\' uh?');

define('ROCKET_LL_VERSION', '2.0.2');
define('ROCKET_LL_VERSION', '2.0.3');
define('ROCKET_LL_WP_VERSION', '4.7');
define('ROCKET_LL_PHP_VERSION', '5.4');
define('ROCKET_LL_BASENAME', plugin_basename(__FILE__));
Expand Down
55 changes: 49 additions & 6 deletions src/Subscriber/LazyloadSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public function getSubscribedEvents()
[ 'insertLazyloadScript', ROCKET_LL_INT_MAX ],
['insertYoutubeThumbnailScript', ROCKET_LL_INT_MAX ],
],
'wp_enqueue_scripts' => ['insertYoutubeThumbnailStyle', ROCKET_LL_INT_MAX],
'wp_enqueue_scripts' => [
['insertNoJSStyle', ROCKET_LL_INT_MAX - 1],
['insertYoutubeThumbnailStyle', ROCKET_LL_INT_MAX],
],
'template_redirect' => ['lazyload', ROCKET_LL_INT_MAX],
'rocket_lazyload_html' => 'lazyloadResponsive',
'init' => 'lazyloadSmilies',
Expand All @@ -107,7 +110,7 @@ public function insertLazyloadScript()
return;
}

if (! $this->shouldlazyload()) { // WPCS: prefix ok.
if (! $this->shouldLazyload()) {
return;
}

Expand Down Expand Up @@ -165,7 +168,7 @@ public function insertYoutubeThumbnailScript()
return;
}

if (! $this->shouldlazyload()) { // WPCS: prefix ok.
if (! $this->shouldLazyload()) {
return;
}

Expand All @@ -186,6 +189,23 @@ public function insertYoutubeThumbnailScript()
);
}

/**
* Inserts the no JS CSS compatibility in the header
*
* @since 2.0.3
* @author Remy Perona
*
* @return void
*/
public function insertNoJSStyle()
{
if (! $this->shouldLazyload()) {
return;
}

$this->assets->insertNoJSCSS();
}

/**
* Inserts the Youtube thumbnail CSS in the header
*
Expand All @@ -200,7 +220,7 @@ public function insertYoutubeThumbnailStyle()
return;
}

if (! $this->shouldlazyload()) {
if (! $this->shouldLazyload()) {
return;
}

Expand All @@ -225,6 +245,16 @@ private function shouldLazyload()
return false;
}

// Don't lazyload on Beaver Builder editor
if (isset($_GET['fl_builder'])) {
return false;
}

// Don't lazyload on Divi editor
if (isset($_GET['et_fb'])) {
return false;
}

/**
* Filters the lazyload application
*
Expand Down Expand Up @@ -268,16 +298,18 @@ public function lazyload()
*/
public function lazyloadBuffer($html)
{
$buffer = $this->ignoreScripts($html);

if ($this->option_array->get('images')) {
$html = $this->image->lazyloadImages($html);
$html = $this->image->lazyloadImages($html, $buffer);
}

if ($this->option_array->get('iframes')) {
$args = [
'youtube' => $this->option_array->get('youtube'),
];

$html = $this->iframe->lazyloadIframes($html, $args);
$html = $this->iframe->lazyloadIframes($html, $buffer, $args);
}

return $html;
Expand Down Expand Up @@ -330,4 +362,15 @@ public function lazyloadSmilies()
add_filter($filter, [$this->image, 'convertSmilies'], $prio);
}
}

/**
* Remove inline scripts from the HTML to parse
*
* @param string $html
* @return string
*/
private function ignoreScripts($html)
{
return preg_replace('/<script\b(?:[^>]*)>(?:.+)?<\/script>/msi', '', $html);
}
}

0 comments on commit 43ffa19

Please sign in to comment.