Lazy Load - Version 0.6

Version Description

  • Filter to control when lazy loading is enabled
Download this release

Release Info

Developer automattic
Plugin Icon wp plugin Lazy Load
Version 0.6
Comparing to
See all releases

Code changes from version 0.5 to 0.6

Files changed (3) hide show
  1. js/lazy-load.js +3 -0
  2. lazy-load.php +22 -4
  3. readme.txt +6 -2
js/lazy-load.js CHANGED
@@ -19,6 +19,9 @@
19
  var $img = jQuery( img ),
20
  src = $img.attr( 'data-lazy-src' );
21
 
 
 
 
22
  $img.unbind( 'scrollin' ) // remove event binding
23
  .hide()
24
  .removeAttr( 'data-lazy-src' )
19
  var $img = jQuery( img ),
20
  src = $img.attr( 'data-lazy-src' );
21
 
22
+ if ( ! src || 'undefined' === typeof( src ) )
23
+ return;
24
+
25
  $img.unbind( 'scrollin' ) // remove event binding
26
  .hide()
27
  .removeAttr( 'data-lazy-src' )
lazy-load.php CHANGED
@@ -2,7 +2,8 @@
2
  /**
3
  * Plugin Name: Lazy Load
4
  * Description: Lazy load images to improve page load times. Uses jQuery.sonar to only load an image when it's visible in the viewport.
5
- * Version: 0.5
 
6
  *
7
  * Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC).
8
  * Uses jQuery.sonar by Dave Artz (AOL): http://www.artzstudio.com/files/jquery-boston-2010/jquery.sonar/
@@ -14,13 +15,23 @@ if ( ! class_exists( 'LazyLoad_Images' ) ) :
14
 
15
  class LazyLoad_Images {
16
 
17
- const version = '0.5';
 
18
 
19
  static function init() {
20
  if ( is_admin() )
21
  return;
22
 
 
 
 
 
 
23
  add_action( 'wp_enqueue_scripts', array( __CLASS__, 'add_scripts' ) );
 
 
 
 
24
  add_filter( 'the_content', array( __CLASS__, 'add_image_placeholders' ), 99 ); // run this later, so other content filters have run, including image_add_wh on WP.com
25
  add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 );
26
  add_filter( 'get_avatar', array( __CLASS__, 'add_image_placeholders' ), 11 );
@@ -32,8 +43,11 @@ class LazyLoad_Images {
32
  }
33
 
34
  static function add_image_placeholders( $content ) {
 
 
 
35
  // Don't lazyload for feeds, previews, mobile
36
- if( is_feed() || is_preview() || ( function_exists( 'is_mobile' ) && is_mobile() ) )
37
  return $content;
38
 
39
  // Don't lazy-load if the content has already been run through previously
@@ -49,6 +63,10 @@ class LazyLoad_Images {
49
  return $content;
50
  }
51
 
 
 
 
 
52
  static function get_url( $path = '' ) {
53
  return plugins_url( ltrim( $path, '/' ), __FILE__ );
54
  }
@@ -58,6 +76,6 @@ function lazyload_images_add_placeholders( $content ) {
58
  return LazyLoad_Images::add_image_placeholders( $content );
59
  }
60
 
61
- LazyLoad_Images::init();
62
 
63
  endif;
2
  /**
3
  * Plugin Name: Lazy Load
4
  * Description: Lazy load images to improve page load times. Uses jQuery.sonar to only load an image when it's visible in the viewport.
5
+ * Version: 0.6
6
+ * Text Domain: lazy-load
7
  *
8
  * Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC).
9
  * Uses jQuery.sonar by Dave Artz (AOL): http://www.artzstudio.com/files/jquery-boston-2010/jquery.sonar/
15
 
16
  class LazyLoad_Images {
17
 
18
+ const version = '0.6';
19
+ protected static $enabled = true;
20
 
21
  static function init() {
22
  if ( is_admin() )
23
  return;
24
 
25
+ if ( ! apply_filters( 'lazyload_is_enabled', true ) ) {
26
+ self::$enabled = false;
27
+ return;
28
+ }
29
+
30
  add_action( 'wp_enqueue_scripts', array( __CLASS__, 'add_scripts' ) );
31
+ add_action( 'wp_head', array( __CLASS__, 'setup_filters' ), 9999 ); // we don't really want to modify anything in <head> since it's mostly all metadata, e.g. OG tags
32
+ }
33
+
34
+ static function setup_filters() {
35
  add_filter( 'the_content', array( __CLASS__, 'add_image_placeholders' ), 99 ); // run this later, so other content filters have run, including image_add_wh on WP.com
36
  add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 );
37
  add_filter( 'get_avatar', array( __CLASS__, 'add_image_placeholders' ), 11 );
43
  }
44
 
45
  static function add_image_placeholders( $content ) {
46
+ if ( ! self::is_enabled() )
47
+ return $content;
48
+
49
  // Don't lazyload for feeds, previews, mobile
50
+ if( is_feed() || is_preview() )
51
  return $content;
52
 
53
  // Don't lazy-load if the content has already been run through previously
63
  return $content;
64
  }
65
 
66
+ static function is_enabled() {
67
+ return self::$enabled;
68
+ }
69
+
70
  static function get_url( $path = '' ) {
71
  return plugins_url( ltrim( $path, '/' ), __FILE__ );
72
  }
76
  return LazyLoad_Images::add_image_placeholders( $content );
77
  }
78
 
79
+ add_action( 'init', array( 'LazyLoad_Images', 'init' ) );
80
 
81
  endif;
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: batmoo, automattic, jakemgold, 10up
3
  Tags: lazy load, images, front-end optimization
4
  Requires at least: 3.2
5
- Tested up to: 3.4.1
6
- Stable tag: 0.5
7
 
8
  Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user.
9
 
@@ -58,6 +58,10 @@ This will lazy load <em>all</em> your images.
58
 
59
  == Changelog ==
60
 
 
 
 
 
61
  = 0.5 =
62
 
63
  * Fix lazyload_images_add_placeholders by adding missing return, props Kevin Smith
2
  Contributors: batmoo, automattic, jakemgold, 10up
3
  Tags: lazy load, images, front-end optimization
4
  Requires at least: 3.2
5
+ Tested up to: 4.5
6
+ Stable tag: 0.6
7
 
8
  Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user.
9
 
58
 
59
  == Changelog ==
60
 
61
+ = 0.6 =
62
+
63
+ * Filter to control when lazy loading is enabled
64
+
65
  = 0.5 =
66
 
67
  * Fix lazyload_images_add_placeholders by adding missing return, props Kevin Smith