Lazy Load by WP Rocket - Version 2.0.3

Version Description

  • 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
Download this release

Release Info

Developer wp_media
Plugin Icon 128x128 Lazy Load by WP Rocket
Version 2.0.3
Comparing to
See all releases

Code changes from version 2.0.2 to 2.0.3

composer.json CHANGED
@@ -36,7 +36,7 @@
36
  "require": {
37
  "php": ">=5.4.0",
38
  "league/container": "^2.4",
39
- "wp-media/rocket-lazyload-common": "^1.0.0"
40
  },
41
  "require-dev": {
42
  "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
36
  "require": {
37
  "php": ">=5.4.0",
38
  "league/container": "^2.4",
39
+ "wp-media/rocket-lazyload-common": "^2.0.0"
40
  },
41
  "require-dev": {
42
  "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
composer.lock CHANGED
@@ -4,7 +4,7 @@
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
  "This file is @generated automatically"
6
  ],
7
- "content-hash": "f29400f3ee27894ea8fb972d21229ce3",
8
  "packages": [
9
  {
10
  "name": "container-interop/container-interop",
@@ -153,16 +153,16 @@
153
  },
154
  {
155
  "name": "wp-media/rocket-lazyload-common",
156
- "version": "v1.3",
157
  "source": {
158
  "type": "git",
159
  "url": "https://github.com/wp-media/rocket-lazyload-common.git",
160
- "reference": "d2492d2e874a8e9fdeaf1c9e8117d5c211fad3cb"
161
  },
162
  "dist": {
163
  "type": "zip",
164
- "url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/d2492d2e874a8e9fdeaf1c9e8117d5c211fad3cb",
165
- "reference": "d2492d2e874a8e9fdeaf1c9e8117d5c211fad3cb",
166
  "shasum": ""
167
  },
168
  "require": {
@@ -188,10 +188,10 @@
188
  ],
189
  "description": "Common Code between WP Rocket and Lazyload by WP Rocket",
190
  "support": {
191
- "source": "https://github.com/wp-media/rocket-lazyload-common/tree/v1.3",
192
  "issues": "https://github.com/wp-media/rocket-lazyload-common/issues"
193
  },
194
- "time": "2019-01-09T17:31:57+00:00"
195
  }
196
  ],
197
  "packages-dev": [
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
  "This file is @generated automatically"
6
  ],
7
+ "content-hash": "7b8ffd2baafae72a52f8be8573399b8e",
8
  "packages": [
9
  {
10
  "name": "container-interop/container-interop",
153
  },
154
  {
155
  "name": "wp-media/rocket-lazyload-common",
156
+ "version": "v2.0",
157
  "source": {
158
  "type": "git",
159
  "url": "https://github.com/wp-media/rocket-lazyload-common.git",
160
+ "reference": "0c834ce26ae8ed41f6f13eb284b5f4c06c18b499"
161
  },
162
  "dist": {
163
  "type": "zip",
164
+ "url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/0c834ce26ae8ed41f6f13eb284b5f4c06c18b499",
165
+ "reference": "0c834ce26ae8ed41f6f13eb284b5f4c06c18b499",
166
  "shasum": ""
167
  },
168
  "require": {
188
  ],
189
  "description": "Common Code between WP Rocket and Lazyload by WP Rocket",
190
  "support": {
191
+ "source": "https://github.com/wp-media/rocket-lazyload-common/tree/v2.0",
192
  "issues": "https://github.com/wp-media/rocket-lazyload-common/issues"
193
  },
194
+ "time": "2019-01-15T21:38:51+00:00"
195
  }
196
  ],
197
  "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.0.2
6
  Requires PHP: 5.4
7
- Stable tag: 2.0.2
8
 
9
  Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.
10
 
@@ -78,6 +78,12 @@ The element you want to apply lazyload on must have this specific markup:
78
  The element must have the class `rocket-lazyload-bg`, and a `data-bg` attribute, which value is the CSS url for the image.
79
 
80
  == Changelog ==
 
 
 
 
 
 
81
  = 2.0.2 =
82
  * Bugfix: Fix an error in the compatibility for the AMP plugin
83
 
4
  Requires at least: 4.7
5
  Tested up to: 5.0.2
6
  Requires PHP: 5.4
7
+ Stable tag: 2.0.3
8
 
9
  Lazy Load your images and iframes, replace Youtube videos by a preview thumbnail.
10
 
78
  The element must have the class `rocket-lazyload-bg`, and a `data-bg` attribute, which value is the CSS url for the image.
79
 
80
  == Changelog ==
81
+ = 2.0.3 =
82
+ * Bugfix: Prevent incorrect display if JavaScript is disabled
83
+ * Bugfix: Don't apply lazyload on Divi/Extra/Beaver Builder Editor pages
84
+ * Bugfix: Use the correct URL for each iframe when multiple iframes are on the same page
85
+ * Bugfix: Ignore content inside inline script tags to prevent applying lazyload in it
86
+
87
  = 2.0.2 =
88
  * Bugfix: Fix an error in the compatibility for the AMP plugin
89
 
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.0.2
7
  * Author: WP Media
8
  * Author URI: https://wp-rocket.me
9
  * Text Domain: rocket-lazy-load
@@ -27,7 +27,7 @@
27
 
28
  defined('ABSPATH') || die('Cheatin\' uh?');
29
 
30
- define('ROCKET_LL_VERSION', '2.0.2');
31
  define('ROCKET_LL_WP_VERSION', '4.7');
32
  define('ROCKET_LL_PHP_VERSION', '5.4');
33
  define('ROCKET_LL_BASENAME', plugin_basename(__FILE__));
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.0.3
7
  * Author: WP Media
8
  * Author URI: https://wp-rocket.me
9
  * Text Domain: rocket-lazy-load
27
 
28
  defined('ABSPATH') || die('Cheatin\' uh?');
29
 
30
+ define('ROCKET_LL_VERSION', '2.0.3');
31
  define('ROCKET_LL_WP_VERSION', '4.7');
32
  define('ROCKET_LL_PHP_VERSION', '5.4');
33
  define('ROCKET_LL_BASENAME', plugin_basename(__FILE__));
src/Subscriber/LazyloadSubscriber.php CHANGED
@@ -86,7 +86,10 @@ class LazyloadSubscriber implements SubscriberInterface
86
  [ 'insertLazyloadScript', ROCKET_LL_INT_MAX ],
87
  ['insertYoutubeThumbnailScript', ROCKET_LL_INT_MAX ],
88
  ],
89
- 'wp_enqueue_scripts' => ['insertYoutubeThumbnailStyle', ROCKET_LL_INT_MAX],
 
 
 
90
  'template_redirect' => ['lazyload', ROCKET_LL_INT_MAX],
91
  'rocket_lazyload_html' => 'lazyloadResponsive',
92
  'init' => 'lazyloadSmilies',
@@ -107,7 +110,7 @@ class LazyloadSubscriber implements SubscriberInterface
107
  return;
108
  }
109
 
110
- if (! $this->shouldlazyload()) { // WPCS: prefix ok.
111
  return;
112
  }
113
 
@@ -165,7 +168,7 @@ class LazyloadSubscriber implements SubscriberInterface
165
  return;
166
  }
167
 
168
- if (! $this->shouldlazyload()) { // WPCS: prefix ok.
169
  return;
170
  }
171
 
@@ -186,6 +189,23 @@ class LazyloadSubscriber implements SubscriberInterface
186
  );
187
  }
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  /**
190
  * Inserts the Youtube thumbnail CSS in the header
191
  *
@@ -200,7 +220,7 @@ class LazyloadSubscriber implements SubscriberInterface
200
  return;
201
  }
202
 
203
- if (! $this->shouldlazyload()) {
204
  return;
205
  }
206
 
@@ -225,6 +245,16 @@ class LazyloadSubscriber implements SubscriberInterface
225
  return false;
226
  }
227
 
 
 
 
 
 
 
 
 
 
 
228
  /**
229
  * Filters the lazyload application
230
  *
@@ -268,8 +298,10 @@ class LazyloadSubscriber implements SubscriberInterface
268
  */
269
  public function lazyloadBuffer($html)
270
  {
 
 
271
  if ($this->option_array->get('images')) {
272
- $html = $this->image->lazyloadImages($html);
273
  }
274
 
275
  if ($this->option_array->get('iframes')) {
@@ -277,7 +309,7 @@ class LazyloadSubscriber implements SubscriberInterface
277
  'youtube' => $this->option_array->get('youtube'),
278
  ];
279
 
280
- $html = $this->iframe->lazyloadIframes($html, $args);
281
  }
282
 
283
  return $html;
@@ -330,4 +362,15 @@ class LazyloadSubscriber implements SubscriberInterface
330
  add_filter($filter, [$this->image, 'convertSmilies'], $prio);
331
  }
332
  }
 
 
 
 
 
 
 
 
 
 
 
333
  }
86
  [ 'insertLazyloadScript', ROCKET_LL_INT_MAX ],
87
  ['insertYoutubeThumbnailScript', ROCKET_LL_INT_MAX ],
88
  ],
89
+ 'wp_enqueue_scripts' => [
90
+ ['insertNoJSStyle', ROCKET_LL_INT_MAX - 1],
91
+ ['insertYoutubeThumbnailStyle', ROCKET_LL_INT_MAX],
92
+ ],
93
  'template_redirect' => ['lazyload', ROCKET_LL_INT_MAX],
94
  'rocket_lazyload_html' => 'lazyloadResponsive',
95
  'init' => 'lazyloadSmilies',
110
  return;
111
  }
112
 
113
+ if (! $this->shouldLazyload()) {
114
  return;
115
  }
116
 
168
  return;
169
  }
170
 
171
+ if (! $this->shouldLazyload()) {
172
  return;
173
  }
174
 
189
  );
190
  }
191
 
192
+ /**
193
+ * Inserts the no JS CSS compatibility in the header
194
+ *
195
+ * @since 2.0.3
196
+ * @author Remy Perona
197
+ *
198
+ * @return void
199
+ */
200
+ public function insertNoJSStyle()
201
+ {
202
+ if (! $this->shouldLazyload()) {
203
+ return;
204
+ }
205
+
206
+ $this->assets->insertNoJSCSS();
207
+ }
208
+
209
  /**
210
  * Inserts the Youtube thumbnail CSS in the header
211
  *
220
  return;
221
  }
222
 
223
+ if (! $this->shouldLazyload()) {
224
  return;
225
  }
226
 
245
  return false;
246
  }
247
 
248
+ // Don't lazyload on Beaver Builder editor
249
+ if (isset($_GET['fl_builder'])) {
250
+ return false;
251
+ }
252
+
253
+ // Don't lazyload on Divi editor
254
+ if (isset($_GET['et_fb'])) {
255
+ return false;
256
+ }
257
+
258
  /**
259
  * Filters the lazyload application
260
  *
298
  */
299
  public function lazyloadBuffer($html)
300
  {
301
+ $buffer = $this->ignoreScripts($html);
302
+
303
  if ($this->option_array->get('images')) {
304
+ $html = $this->image->lazyloadImages($html, $buffer);
305
  }
306
 
307
  if ($this->option_array->get('iframes')) {
309
  'youtube' => $this->option_array->get('youtube'),
310
  ];
311
 
312
+ $html = $this->iframe->lazyloadIframes($html, $buffer, $args);
313
  }
314
 
315
  return $html;
362
  add_filter($filter, [$this->image, 'convertSmilies'], $prio);
363
  }
364
  }
365
+
366
+ /**
367
+ * Remove inline scripts from the HTML to parse
368
+ *
369
+ * @param string $html
370
+ * @return string
371
+ */
372
+ private function ignoreScripts($html)
373
+ {
374
+ return preg_replace('/<script\b(?:[^>]*)>(?:.+)?<\/script>/msi', '', $html);
375
+ }
376
  }
vendor/composer/installed.json CHANGED
@@ -152,17 +152,17 @@
152
  },
153
  {
154
  "name": "wp-media/rocket-lazyload-common",
155
- "version": "v1.3",
156
- "version_normalized": "1.3.0.0",
157
  "source": {
158
  "type": "git",
159
  "url": "https://github.com/wp-media/rocket-lazyload-common.git",
160
- "reference": "d2492d2e874a8e9fdeaf1c9e8117d5c211fad3cb"
161
  },
162
  "dist": {
163
  "type": "zip",
164
- "url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/d2492d2e874a8e9fdeaf1c9e8117d5c211fad3cb",
165
- "reference": "d2492d2e874a8e9fdeaf1c9e8117d5c211fad3cb",
166
  "shasum": ""
167
  },
168
  "require": {
@@ -171,7 +171,7 @@
171
  "require-dev": {
172
  "squizlabs/php_codesniffer": "^3.2"
173
  },
174
- "time": "2019-01-09T17:31:57+00:00",
175
  "type": "library",
176
  "installation-source": "dist",
177
  "autoload": {
@@ -190,7 +190,7 @@
190
  ],
191
  "description": "Common Code between WP Rocket and Lazyload by WP Rocket",
192
  "support": {
193
- "source": "https://github.com/wp-media/rocket-lazyload-common/tree/v1.3",
194
  "issues": "https://github.com/wp-media/rocket-lazyload-common/issues"
195
  }
196
  }
152
  },
153
  {
154
  "name": "wp-media/rocket-lazyload-common",
155
+ "version": "v2.0",
156
+ "version_normalized": "2.0.0.0",
157
  "source": {
158
  "type": "git",
159
  "url": "https://github.com/wp-media/rocket-lazyload-common.git",
160
+ "reference": "0c834ce26ae8ed41f6f13eb284b5f4c06c18b499"
161
  },
162
  "dist": {
163
  "type": "zip",
164
+ "url": "https://api.github.com/repos/wp-media/rocket-lazyload-common/zipball/0c834ce26ae8ed41f6f13eb284b5f4c06c18b499",
165
+ "reference": "0c834ce26ae8ed41f6f13eb284b5f4c06c18b499",
166
  "shasum": ""
167
  },
168
  "require": {
171
  "require-dev": {
172
  "squizlabs/php_codesniffer": "^3.2"
173
  },
174
+ "time": "2019-01-15T21:38:51+00:00",
175
  "type": "library",
176
  "installation-source": "dist",
177
  "autoload": {
190
  ],
191
  "description": "Common Code between WP Rocket and Lazyload by WP Rocket",
192
  "support": {
193
+ "source": "https://github.com/wp-media/rocket-lazyload-common/tree/v2.0",
194
  "issues": "https://github.com/wp-media/rocket-lazyload-common/issues"
195
  }
196
  }
vendor/wp-media/rocket-lazyload-common/src/Assets.php CHANGED
@@ -109,6 +109,16 @@ HTML;
109
 
110
  $css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;cursor:pointer;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:72px;width:72px;left:50%;top:50%;margin-left:-36px;margin-top:-36px;position:absolute;background:url(' . $args['base_url'] . 'img/youtube.png) no-repeat;cursor:pointer}.wp-has-aspect-ratio .rll-youtube-player{position:absolute;padding-bottom:0;width:100%;height:100%;top:0;bottom:0;left:0;right:0;';
111
 
 
 
 
 
 
 
 
 
 
 
112
  wp_register_style('rocket-lazyload', false);
113
  wp_enqueue_style('rocket-lazyload');
114
  wp_add_inline_style('rocket-lazyload', $css);
109
 
110
  $css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;cursor:pointer;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:72px;width:72px;left:50%;top:50%;margin-left:-36px;margin-top:-36px;position:absolute;background:url(' . $args['base_url'] . 'img/youtube.png) no-repeat;cursor:pointer}.wp-has-aspect-ratio .rll-youtube-player{position:absolute;padding-bottom:0;width:100%;height:100%;top:0;bottom:0;left:0;right:0;';
111
 
112
+ wp_add_inline_style('rocket-lazyload', $css);
113
+ }
114
+
115
+ /**
116
+ * Inserts the CSS needed when Javascript is not enabled to keep the display correct
117
+ */
118
+ public function insertNoJSCSS()
119
+ {
120
+ $css = '.no-js .rll-youtube-player, .no-js [data-lazy-src]{display:none !important;}';
121
+
122
  wp_register_style('rocket-lazyload', false);
123
  wp_enqueue_style('rocket-lazyload');
124
  wp_add_inline_style('rocket-lazyload', $css);
vendor/wp-media/rocket-lazyload-common/src/Iframe.php CHANGED
@@ -9,11 +9,12 @@ class Iframe
9
  /**
10
  * Finds iframes in the HTML provided and call the methods to lazyload them
11
  *
12
- * @param string $html HTML to parse
 
13
  * @param array $args Array of arguments to use
14
  * @return string
15
  */
16
- public function lazyloadIframes($html, $args)
17
  {
18
  $defaults = [
19
  'youtube' => false,
@@ -21,7 +22,7 @@ class Iframe
21
 
22
  $args = wp_parse_args($args, $defaults);
23
 
24
- preg_match_all('@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $html, $matches, PREG_SET_ORDER);
25
 
26
  if (empty($matches)) {
27
  return $html;
@@ -52,6 +53,8 @@ class Iframe
52
  }
53
 
54
  $html = str_replace($iframe[0], $iframe_lazyload, $html);
 
 
55
  }
56
 
57
  return $html;
@@ -94,7 +97,7 @@ class Iframe
94
  /**
95
  * Filter the LazyLoad placeholder on src attribute
96
  *
97
- * @since 2.11
98
  *
99
  * @param string $placeholder placeholder that will be printed.
100
  */
@@ -106,7 +109,7 @@ class Iframe
106
  /**
107
  * Filter the LazyLoad HTML output on iframes
108
  *
109
- * @since 2.11
110
  *
111
  * @param array $html Output that will be printed.
112
  */
9
  /**
10
  * Finds iframes in the HTML provided and call the methods to lazyload them
11
  *
12
+ * @param string $html Original HTML
13
+ * @param string $buffer Content to parse
14
  * @param array $args Array of arguments to use
15
  * @return string
16
  */
17
+ public function lazyloadIframes($html, $buffer, $args)
18
  {
19
  $defaults = [
20
  'youtube' => false,
22
 
23
  $args = wp_parse_args($args, $defaults);
24
 
25
+ preg_match_all('@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $buffer, $matches, PREG_SET_ORDER);
26
 
27
  if (empty($matches)) {
28
  return $html;
53
  }
54
 
55
  $html = str_replace($iframe[0], $iframe_lazyload, $html);
56
+
57
+ unset($iframe_lazyload);
58
  }
59
 
60
  return $html;
97
  /**
98
  * Filter the LazyLoad placeholder on src attribute
99
  *
100
+ * @since 1.0
101
  *
102
  * @param string $placeholder placeholder that will be printed.
103
  */
109
  /**
110
  * Filter the LazyLoad HTML output on iframes
111
  *
112
+ * @since 1.0
113
  *
114
  * @param array $html Output that will be printed.
115
  */
vendor/wp-media/rocket-lazyload-common/src/Image.php CHANGED
@@ -10,89 +10,88 @@ class Image
10
  * Finds the images to be lazyloaded and call the callback method to replace them.
11
  *
12
  * @param string $html
 
13
  * @return string
14
  */
15
- public function lazyloadImages($html)
16
  {
17
- return preg_replace_callback('#<img([^>]*) src=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))([^>]*)>#', [$this,'imageReplaceCallback'], $html);
18
- }
19
 
20
- /**
21
- * Modifies the HTML image tag provided to apply lazyload on it.
22
- *
23
- * @param array $image Array of matching patterns.
24
- * @return string
25
- */
26
- private function imageReplaceCallback($image)
27
- {
28
- // Don't apply LazyLoad on images from WP Retina x2.
29
- if (function_exists('wr2x_picture_rewrite')) {
30
- if (wr2x_get_retina(trailingslashit(ABSPATH) . wr2x_get_pathinfo_from_image_src(trim($image[2], '"')))) {
31
- return $image[0];
32
- }
33
  }
34
 
35
- /**
36
- * Filters the attributes used to prevent lazylad from being applied
37
- *
38
- * @since 2.11
39
- * @author Remy Perona
40
- *
41
- * @param array $excluded_attributes An array of excluded attributes.
42
- */
43
- $excluded_attributes = apply_filters(
44
- 'rocket_lazyload_excluded_attributes',
45
- [
46
- 'data-src=',
47
- 'data-no-lazy=',
48
- 'data-lazy-original=',
49
- 'data-lazy-src=',
50
- 'data-lazysrc=',
51
- 'data-lazyload=',
52
- 'data-bgposition=',
53
- 'data-envira-src=',
54
- 'fullurl=',
55
- 'lazy-slider-img=',
56
- 'data-srcset=',
57
- 'class="ls-l',
58
- 'class="ls-bg',
59
- ]
60
- );
61
 
62
- /**
63
- * Filters the src used to prevent lazylad from being applied
64
- *
65
- * @since 2.11
66
- * @author Remy Perona
67
- *
68
- * @param array $excluded_src An array of excluded src.
69
- */
70
- $excluded_src = apply_filters(
71
- 'rocket_lazyload_excluded_src',
72
- [
73
- '/wpcf7_captcha/',
74
- 'timthumb.php?src',
75
- ]
76
- );
77
-
78
- if ($this->isExcluded($image[1] . $image[3], $excluded_attributes) || $this->isExcluded($image[2], $excluded_src)) {
79
- return $image[0];
80
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- $html = sprintf('<img%1$s src="%4$s" data-lazy-src=%2$s%3$s>', $image[1], $image[2], $image[3], $this->getPlaceholder());
83
 
84
- $html_noscript = sprintf('<noscript><img%1$s src=%2$s%3$s></noscript>', $image[1], $image[2], $image[3]);
 
 
 
 
 
 
 
 
85
 
86
- /**
87
- * Filter the LazyLoad HTML output
88
- *
89
- * @since 1.0.2
90
- *
91
- * @param array $html Output that will be printed
92
- */
93
- $html = apply_filters('rocket_lazyload_html', $html);
94
 
95
- return $html . $html_noscript;
96
  }
97
 
98
  /**
10
  * Finds the images to be lazyloaded and call the callback method to replace them.
11
  *
12
  * @param string $html
13
+ * @param string $buffer
14
  * @return string
15
  */
16
+ public function lazyloadImages($html, $buffer)
17
  {
18
+ preg_match_all('#<img([^>]*) src=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))([^>]*)>#', $buffer, $images, PREG_SET_ORDER);
 
19
 
20
+ if (empty($images)) {
21
+ return $html;
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
 
24
+ foreach ($images as $image) {
25
+ // Don't apply LazyLoad on images from WP Retina x2.
26
+ if (function_exists('wr2x_picture_rewrite')) {
27
+ if (wr2x_get_retina(trailingslashit(ABSPATH) . wr2x_get_pathinfo_from_image_src(trim($image[2], '"')))) {
28
+ continue;
29
+ }
30
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ /**
33
+ * Filters the attributes used to prevent lazylad from being applied
34
+ *
35
+ * @since 1.0
36
+ * @author Remy Perona
37
+ *
38
+ * @param array $excluded_attributes An array of excluded attributes.
39
+ */
40
+ $excluded_attributes = apply_filters(
41
+ 'rocket_lazyload_excluded_attributes',
42
+ [
43
+ 'data-src=',
44
+ 'data-no-lazy=',
45
+ 'data-lazy-original=',
46
+ 'data-lazy-src=',
47
+ 'data-lazysrc=',
48
+ 'data-lazyload=',
49
+ 'data-bgposition=',
50
+ 'data-envira-src=',
51
+ 'fullurl=',
52
+ 'lazy-slider-img=',
53
+ 'data-srcset=',
54
+ 'class="ls-l',
55
+ 'class="ls-bg',
56
+ ]
57
+ );
58
+
59
+ /**
60
+ * Filters the src used to prevent lazylad from being applied
61
+ *
62
+ * @since 1.0
63
+ * @author Remy Perona
64
+ *
65
+ * @param array $excluded_src An array of excluded src.
66
+ */
67
+ $excluded_src = apply_filters(
68
+ 'rocket_lazyload_excluded_src',
69
+ [
70
+ '/wpcf7_captcha/',
71
+ 'timthumb.php?src',
72
+ ]
73
+ );
74
+
75
+ if ($this->isExcluded($image[1] . $image[3], $excluded_attributes) || $this->isExcluded($image[2], $excluded_src)) {
76
+ continue;
77
+ }
78
 
79
+ $image_lazyload = sprintf('<img%1$s src="%4$s" data-lazy-src=%2$s%3$s>', $image[1], $image[2], $image[3], $this->getPlaceholder());
80
 
81
+ /**
82
+ * Filter the LazyLoad HTML output
83
+ *
84
+ * @since 1.0
85
+ *
86
+ * @param string $html Output that will be printed
87
+ */
88
+ $image_lazyload = apply_filters('rocket_lazyload_html', $image_lazyload);
89
+ $image_lazyload .= '<noscript>' . $image[0] . '</noscript>';
90
 
91
+ $html = str_replace($image[0], $image_lazyload, $html);
92
+ }
 
 
 
 
 
 
93
 
94
+ return $html;
95
  }
96
 
97
  /**