From 8db4d8d01f75e23a8302375d5920fd0936ac816c Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Fri, 21 Oct 2016 10:22:00 -0400 Subject: [PATCH 1/2] Added data-lazy-src attribute to img tag and added noscript tag to allowed html so they aren't stripped out by wp_kses_post. --- lazy-load.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lazy-load.php b/lazy-load.php index b80398b..8b7904c 100644 --- a/lazy-load.php +++ b/lazy-load.php @@ -35,6 +35,7 @@ static function setup_filters() { 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 add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 ); add_filter( 'get_avatar', array( __CLASS__, 'add_image_placeholders' ), 11 ); + add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allowed_post_tags' ), 10, 2 ); } static function add_scripts() { @@ -102,6 +103,14 @@ static function is_enabled() { static function get_url( $path = '' ) { return plugins_url( ltrim( $path, '/' ), __FILE__ ); } + + public function allowed_post_tags( $allowedposttags, $context ) { + if ( 'post' === $context && ! empty( $allowedposttags['img'] ) ) { + $allowedposttags['img']['data-lazy-src'] = true; + $allowedposttags['noscript'] = array(); + } + return $allowedposttags; + } } function lazyload_images_add_placeholders( $content ) { From a2a61124ad8ced7afa7263f1928f48e7c4e051dd Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Sat, 22 Oct 2016 07:11:22 -0400 Subject: [PATCH 2/2] Added an opt-in filter for allowing HTML post tags for lazy load. --- lazy-load.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lazy-load.php b/lazy-load.php index 8b7904c..0058c3b 100644 --- a/lazy-load.php +++ b/lazy-load.php @@ -35,7 +35,10 @@ static function setup_filters() { 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 add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 ); add_filter( 'get_avatar', array( __CLASS__, 'add_image_placeholders' ), 11 ); - add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allowed_post_tags' ), 10, 2 ); + + if ( apply_filters( 'lazy_load_kses_allowed_html', false ) ) { + add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allowed_post_tags' ), 10, 2 ); + } } static function add_scripts() {