Version Description
- Bugfix: Correctly apply lazyload on
pictureelements - Bugfix: Prevent double loading of an image when an
imgelement inside apictureelement only has asrcsetattribute and nosrcattribute
Download this release
Release Info
| Developer | wp_media |
| Plugin | |
| Version | 2.1.1 |
| Comparing to | |
| See all releases | |
Code changes from version 2.1 to 2.1.1
- composer.lock +5 -5
- readme.txt +5 -1
- rocket-lazy-load.php +1 -1
- src/Subscriber/LazyloadSubscriber.php +1 -1
- vendor/composer/installed.json +6 -6
- vendor/wp-media/rocket-lazyload-common/src/Image.php +29 -18
composer.lock
CHANGED
|
@@ -273,16 +273,16 @@
|
|
| 273 |
},
|
| 274 |
{
|
| 275 |
"name": "wp-media/rocket-lazyload-common",
|
| 276 |
-
"version": "v2.2.
|
| 277 |
"source": {
|
| 278 |
"type": "git",
|
| 279 |
"url": "https://github.com/wp-media/rocket-lazyload-common.git",
|
| 280 |
-
"reference": "
|
| 281 |
},
|
| 282 |
"dist": {
|
| 283 |
"type": "zip",
|
| 284 |
-
"url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/
|
| 285 |
-
"reference": "
|
| 286 |
"shasum": ""
|
| 287 |
},
|
| 288 |
"require": {
|
|
@@ -317,7 +317,7 @@
|
|
| 317 |
}
|
| 318 |
],
|
| 319 |
"description": "Common Code between WP Rocket and Lazyload by WP Rocket",
|
| 320 |
-
"time": "2019-02-
|
| 321 |
}
|
| 322 |
],
|
| 323 |
"packages-dev": [
|
| 273 |
},
|
| 274 |
{
|
| 275 |
"name": "wp-media/rocket-lazyload-common",
|
| 276 |
+
"version": "v2.2.2",
|
| 277 |
"source": {
|
| 278 |
"type": "git",
|
| 279 |
"url": "https://github.com/wp-media/rocket-lazyload-common.git",
|
| 280 |
+
"reference": "6ea6abc019402042f8a0d578bd3db5dd2a8aba88"
|
| 281 |
},
|
| 282 |
"dist": {
|
| 283 |
"type": "zip",
|
| 284 |
+
"url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/6ea6abc019402042f8a0d578bd3db5dd2a8aba88",
|
| 285 |
+
"reference": "6ea6abc019402042f8a0d578bd3db5dd2a8aba88",
|
| 286 |
"shasum": ""
|
| 287 |
},
|
| 288 |
"require": {
|
| 317 |
}
|
| 318 |
],
|
| 319 |
"description": "Common Code between WP Rocket and Lazyload by WP Rocket",
|
| 320 |
+
"time": "2019-02-27T20:31:03+00:00"
|
| 321 |
}
|
| 322 |
],
|
| 323 |
"packages-dev": [
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Tags: lazyload, lazy load, images, iframes, thumbnail, thumbnails, smiley, smili
|
|
| 4 |
Requires at least: 4.7
|
| 5 |
Tested up to: 5.1
|
| 6 |
Requires PHP: 5.4
|
| 7 |
-
Stable tag: 2.1
|
| 8 |
|
| 9 |
Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.
|
| 10 |
|
|
@@ -85,6 +85,10 @@ You can also apply it manually. The element you want to apply lazyload on must h
|
|
| 85 |
The element must have the class `rocket-lazyload-bg`, and a `data-bg` attribute, which value is the CSS url for the image.
|
| 86 |
|
| 87 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
= 2.1 =
|
| 89 |
* Enhancement: Update lazyload script to the latest version
|
| 90 |
* Enhancement: Apply lazyload on picture elements found on the page
|
| 4 |
Requires at least: 4.7
|
| 5 |
Tested up to: 5.1
|
| 6 |
Requires PHP: 5.4
|
| 7 |
+
Stable tag: 2.1.1
|
| 8 |
|
| 9 |
Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.
|
| 10 |
|
| 85 |
The element must have the class `rocket-lazyload-bg`, and a `data-bg` attribute, which value is the CSS url for the image.
|
| 86 |
|
| 87 |
== Changelog ==
|
| 88 |
+
= 2.1.1 =
|
| 89 |
+
* Bugfix: Correctly apply lazyload on `picture` elements
|
| 90 |
+
* Bugfix: Prevent double loading of an image when an `img` element inside a `picture` element only has a `srcset` attribute and no `src` attribute
|
| 91 |
+
|
| 92 |
= 2.1 =
|
| 93 |
* Enhancement: Update lazyload script to the latest version
|
| 94 |
* Enhancement: Apply lazyload on picture elements found on the page
|
rocket-lazy-load.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
* Plugin Name: Lazy Load by WP Rocket
|
| 4 |
* Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
|
| 5 |
* Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
|
| 6 |
-
* Version: 2.1
|
| 7 |
* Author: WP Rocket
|
| 8 |
* Author URI: https://wp-rocket.me
|
| 9 |
* Text Domain: rocket-lazy-load
|
| 3 |
* Plugin Name: Lazy Load by WP Rocket
|
| 4 |
* Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
|
| 5 |
* Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
|
| 6 |
+
* Version: 2.1.1
|
| 7 |
* Author: WP Rocket
|
| 8 |
* Author URI: https://wp-rocket.me
|
| 9 |
* Text Domain: rocket-lazy-load
|
src/Subscriber/LazyloadSubscriber.php
CHANGED
|
@@ -138,7 +138,7 @@ class LazyloadSubscriber implements SubscriberInterface
|
|
| 138 |
|
| 139 |
if ($this->option_array->get('images')) {
|
| 140 |
$args['elements']['image'] = 'img[data-lazy-src]';
|
| 141 |
-
$args['elements']['background_image'] = '.rocket-lazyload
|
| 142 |
}
|
| 143 |
|
| 144 |
if ($this->option_array->get('iframes')) {
|
| 138 |
|
| 139 |
if ($this->option_array->get('images')) {
|
| 140 |
$args['elements']['image'] = 'img[data-lazy-src]';
|
| 141 |
+
$args['elements']['background_image'] = '.rocket-lazyload';
|
| 142 |
}
|
| 143 |
|
| 144 |
if ($this->option_array->get('iframes')) {
|
vendor/composer/installed.json
CHANGED
|
@@ -274,17 +274,17 @@
|
|
| 274 |
},
|
| 275 |
{
|
| 276 |
"name": "wp-media/rocket-lazyload-common",
|
| 277 |
-
"version": "v2.2.
|
| 278 |
-
"version_normalized": "2.2.
|
| 279 |
"source": {
|
| 280 |
"type": "git",
|
| 281 |
"url": "https://github.com/wp-media/rocket-lazyload-common.git",
|
| 282 |
-
"reference": "
|
| 283 |
},
|
| 284 |
"dist": {
|
| 285 |
"type": "zip",
|
| 286 |
-
"url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/
|
| 287 |
-
"reference": "
|
| 288 |
"shasum": ""
|
| 289 |
},
|
| 290 |
"require": {
|
|
@@ -302,7 +302,7 @@
|
|
| 302 |
"symfony/yaml": "2.8.*",
|
| 303 |
"wp-coding-standards/wpcs": "^2.0.0"
|
| 304 |
},
|
| 305 |
-
"time": "2019-02-
|
| 306 |
"type": "library",
|
| 307 |
"installation-source": "dist",
|
| 308 |
"autoload": {
|
| 274 |
},
|
| 275 |
{
|
| 276 |
"name": "wp-media/rocket-lazyload-common",
|
| 277 |
+
"version": "v2.2.2",
|
| 278 |
+
"version_normalized": "2.2.2.0",
|
| 279 |
"source": {
|
| 280 |
"type": "git",
|
| 281 |
"url": "https://github.com/wp-media/rocket-lazyload-common.git",
|
| 282 |
+
"reference": "6ea6abc019402042f8a0d578bd3db5dd2a8aba88"
|
| 283 |
},
|
| 284 |
"dist": {
|
| 285 |
"type": "zip",
|
| 286 |
+
"url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/6ea6abc019402042f8a0d578bd3db5dd2a8aba88",
|
| 287 |
+
"reference": "6ea6abc019402042f8a0d578bd3db5dd2a8aba88",
|
| 288 |
"shasum": ""
|
| 289 |
},
|
| 290 |
"require": {
|
| 302 |
"symfony/yaml": "2.8.*",
|
| 303 |
"wp-coding-standards/wpcs": "^2.0.0"
|
| 304 |
},
|
| 305 |
+
"time": "2019-02-27T20:31:03+00:00",
|
| 306 |
"type": "library",
|
| 307 |
"installation-source": "dist",
|
| 308 |
"autoload": {
|
vendor/wp-media/rocket-lazyload-common/src/Image.php
CHANGED
|
@@ -78,7 +78,7 @@ class Image
|
|
| 78 |
continue;
|
| 79 |
}
|
| 80 |
|
| 81 |
-
$lazy_bg = $this->
|
| 82 |
$lazy_bg = str_replace($url[0], '', $lazy_bg);
|
| 83 |
$lazy_bg = str_replace('<div', '<div data-bg="url(' . esc_attr($url['url']) . ')"', $lazy_bg);
|
| 84 |
|
|
@@ -95,16 +95,16 @@ class Image
|
|
| 95 |
* @param string $element Element to add the class to.
|
| 96 |
* @return string
|
| 97 |
*/
|
| 98 |
-
private function
|
| 99 |
{
|
| 100 |
if (preg_match('#class=["\']?(?<classes>[^"\'>]*)["\']?#is', $element, $class)) {
|
| 101 |
-
$classes = str_replace($class['classes'], $class['classes'] . ' rocket-lazyload
|
| 102 |
$element = str_replace($class[0], $classes, $element);
|
| 103 |
|
| 104 |
return $element;
|
| 105 |
}
|
| 106 |
|
| 107 |
-
return
|
| 108 |
}
|
| 109 |
|
| 110 |
/**
|
|
@@ -116,9 +116,7 @@ class Image
|
|
| 116 |
*/
|
| 117 |
public function lazyloadPictures($html, $buffer)
|
| 118 |
{
|
| 119 |
-
preg_match_all('#<picture(?:.*)?>(?<sources>.*)</picture>#iUs', $buffer, $pictures, PREG_SET_ORDER)
|
| 120 |
-
|
| 121 |
-
if (empty($pictures)) {
|
| 122 |
return $html;
|
| 123 |
}
|
| 124 |
|
|
@@ -126,24 +124,37 @@ class Image
|
|
| 126 |
$excluded = array_merge($this->getExcludedAttributes(), $this->getExcludedSrc());
|
| 127 |
|
| 128 |
foreach ($pictures as $picture) {
|
| 129 |
-
preg_match_all('#<source(?<atts>\s.+)>#iUs', $picture['sources'], $sources, PREG_SET_ORDER)
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
-
continue;
|
| 133 |
-
}
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
}
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
-
|
|
|
|
| 146 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
return $html;
|
| 78 |
continue;
|
| 79 |
}
|
| 80 |
|
| 81 |
+
$lazy_bg = $this->addLazyCLass($element[0]);
|
| 82 |
$lazy_bg = str_replace($url[0], '', $lazy_bg);
|
| 83 |
$lazy_bg = str_replace('<div', '<div data-bg="url(' . esc_attr($url['url']) . ')"', $lazy_bg);
|
| 84 |
|
| 95 |
* @param string $element Element to add the class to.
|
| 96 |
* @return string
|
| 97 |
*/
|
| 98 |
+
private function addLazyClass($element)
|
| 99 |
{
|
| 100 |
if (preg_match('#class=["\']?(?<classes>[^"\'>]*)["\']?#is', $element, $class)) {
|
| 101 |
+
$classes = str_replace($class['classes'], $class['classes'] . ' rocket-lazyload', $class[0]);
|
| 102 |
$element = str_replace($class[0], $classes, $element);
|
| 103 |
|
| 104 |
return $element;
|
| 105 |
}
|
| 106 |
|
| 107 |
+
return preg_replace('#<(img|div)([^>]*)>#is', '<\1 class="rocket-lazyload"\2>', $element);
|
| 108 |
}
|
| 109 |
|
| 110 |
/**
|
| 116 |
*/
|
| 117 |
public function lazyloadPictures($html, $buffer)
|
| 118 |
{
|
| 119 |
+
if (! preg_match_all('#<picture(?:.*)?>(?<sources>.*)</picture>#iUs', $buffer, $pictures, PREG_SET_ORDER) ) {
|
|
|
|
|
|
|
| 120 |
return $html;
|
| 121 |
}
|
| 122 |
|
| 124 |
$excluded = array_merge($this->getExcludedAttributes(), $this->getExcludedSrc());
|
| 125 |
|
| 126 |
foreach ($pictures as $picture) {
|
| 127 |
+
if (preg_match_all('#<source(?<atts>\s.+)>#iUs', $picture['sources'], $sources, PREG_SET_ORDER)) {
|
| 128 |
+
$sources = array_unique($sources, SORT_REGULAR);
|
| 129 |
|
| 130 |
+
$lazy_sources = 0;
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
foreach ($sources as $source) {
|
| 133 |
+
if ($this->isExcluded($source['atts'], $excluded)) {
|
| 134 |
+
continue;
|
| 135 |
+
}
|
| 136 |
|
| 137 |
+
$lazyload_srcset = preg_replace('/([\s"\'])srcset/i', '\1data-lazy-srcset', $source[0]);
|
| 138 |
+
$html = str_replace($source[0], $lazyload_srcset, $html);
|
| 139 |
+
|
| 140 |
+
unset($lazyload_srcset);
|
| 141 |
+
$lazy_sources++;
|
| 142 |
}
|
| 143 |
+
}
|
| 144 |
|
| 145 |
+
if (0 === $lazy_sources) {
|
| 146 |
+
continue;
|
| 147 |
+
}
|
| 148 |
|
| 149 |
+
if (! preg_match('#<img(?:[^>]*)>#is', $picture[0], $img)) {
|
| 150 |
+
continue;
|
| 151 |
}
|
| 152 |
+
|
| 153 |
+
$img_lazy = preg_replace('/([\s"\'])srcset/i', '\1data-lazy-src', $img[0]);
|
| 154 |
+
$img_lazy = $this->addLazyClass($img_lazy);
|
| 155 |
+
$html = str_replace($img[0], $img_lazy, $html);
|
| 156 |
+
|
| 157 |
+
unset($img_lazy);
|
| 158 |
}
|
| 159 |
|
| 160 |
return $html;
|
