Title: Bug with quotation in sprintf
Last modified: April 9, 2018

---

# Bug with quotation in sprintf

 *  [juslintek](https://wordpress.org/support/users/juslintek/)
 * (@juslintek)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/bug-with-brackets/)
 * Found a bug, which causes unescapable quotes.
    [https://plugins.trac.wordpress.org/browser/rocket-lazy-load/tags/1.4.7/rocket-lazy-load.php#L272](https://plugins.trac.wordpress.org/browser/rocket-lazy-load/tags/1.4.7/rocket-lazy-load.php#L272)
 * should be:
 *     ```
       $img = sprintf( '<img%1$s src=%4$s data-lazy-src=%2$s%3$s>', $matches[1], $matches[2], $matches[3], $placeholder );
       ```
   
 * This breaks json formatting.
    -  This topic was modified 8 years, 2 months ago by [juslintek](https://wordpress.org/support/users/juslintek/).
    -  This topic was modified 8 years, 2 months ago by [juslintek](https://wordpress.org/support/users/juslintek/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [juslintek](https://wordpress.org/support/users/juslintek/)
 * (@juslintek)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/bug-with-brackets/#post-10160556)
 * If someone has same issue and want temporary fix without hardcoding then, put
   this code in your theme functions.php
 *     ```
       remove_filter( 'get_avatar'         , 'rocket_lazyload_images', PHP_INT_MAX );
       remove_filter( 'the_content'        , 'rocket_lazyload_images', PHP_INT_MAX );
       remove_filter( 'widget_text'        , 'rocket_lazyload_images', PHP_INT_MAX );
       remove_filter( 'get_image_tag'      , 'rocket_lazyload_images', PHP_INT_MAX );
       remove_filter( 'post_thumbnail_html', 'rocket_lazyload_images', PHP_INT_MAX );
   
       function rocket_lazyload_images_override( $html ) {
       	// Don't LazyLoad if the thumbnail is in admin, a feed, REST API or a post preview.
       	if ( ! rocket_lazyload_get_option( 'images' ) || is_admin() || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || empty( $html ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) || wp_script_is( 'twentytwenty-twentytwenty', 'enqueued' ) ) {
       		return $html;
       	}
   
       	// You can stop the LalyLoad process with a hook.
       	if ( ! apply_filters( 'do_rocket_lazyload', true ) ) {
       		return $html;
       	}
   
       	return preg_replace_callback( '#<img([^>]*) src=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))([^>]*)>#', 'rocket_lazyload_replace_callback_fix', $html );
       }
       add_filter( 'get_avatar'         , 'rocket_lazyload_images_override', PHP_INT_MAX );
       add_filter( 'the_content'        , 'rocket_lazyload_images_override', PHP_INT_MAX );
       add_filter( 'widget_text'        , 'rocket_lazyload_images_override', PHP_INT_MAX );
       add_filter( 'get_image_tag'      , 'rocket_lazyload_images_override', PHP_INT_MAX );
       add_filter( 'post_thumbnail_html', 'rocket_lazyload_images_override', PHP_INT_MAX );
   
       /**
        * Used to check if we have to LazyLoad this or not
        *
        * @since 1.1 Don't apply LazyLoad on images from WP Retina x2
        * @since 1.0.1
        *
        * @param string $matches a string matching the pattern to find images in HTML code.
        * @return string Updated string with lazyload data
        */
       function rocket_lazyload_replace_callback_fix( $matches ) {
       	if ( function_exists( 'wr2x_picture_rewrite' ) ) {
       		if ( wr2x_get_retina( trailingslashit( ABSPATH ) . wr2x_get_pathinfo_from_image_src( trim( $matches[2], '"' ) ) ) ) {
       			return $matches[0];
       		}
       	}
       	$excluded_attributes = apply_filters( 'rocket_lazyload_excluded_attributes', array(
       		'data-no-lazy=',
       		'data-lazy-original=',
       		'data-lazy-src=',
       		'data-src=',
       		'data-lazysrc=',
       		'data-lazyload=',
       		'data-bgposition=',
       		'data-envira-src=',
       		'fullurl=',
       		'lazy-slider-img=',
       		'data-srcset=',
       		'class="ls-l',
       		'class="ls-bg',
       	) );
   
       	$excluded_src = apply_filters( 'rocket_lazyload_excluded_src', array(
       		'/wpcf7_captcha/',
       		'timthumb.php?src',
       	) );
   
       	if ( rocket_is_excluded_lazyload( $matches[1] . $matches[3], $excluded_attributes ) ||  rocket_is_excluded_lazyload( $matches[2], $excluded_src ) ) {
       		return $matches[0];
       	}
   
       	/**
       	 * Filter the LazyLoad placeholder on src attribute
       	 *
       	 * @since 1.1
       	 *
       	 * @param string $placeholder Placeholder that will be printed.
       	 */
       	$placeholder = apply_filters( 'rocket_lazyload_placeholder', "data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" );
   
       	$img = sprintf( '<img%1$s src=%4$s data-lazy-src=%2$s%3$s>', $matches[1], $matches[2], $matches[3], $placeholder );
   
       	$img_noscript = sprintf( '<noscript><img%1$s src=%2$s%3$s></noscript>', $matches[1], $matches[2], $matches[3] );
   
       	/**
       	 * Filter the LazyLoad HTML output
       	 *
       	 * @since 1.0.2
       	 *
       	 * @param array $img Output that will be printed
       	 */
       	$img = apply_filters( 'rocket_lazyload_html', $img, true );
   
       	return $img . $img_noscript;
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Bug with quotation in sprintf’ is closed to new replies.

 * ![](https://ps.w.org/rocket-lazy-load/assets/icon-256x256.png?rev=2715509)
 * [LazyLoad Plugin – Lazy Load Images, Videos, and Iframes](https://wordpress.org/plugins/rocket-lazy-load/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/rocket-lazy-load/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/rocket-lazy-load/)
 * [Active Topics](https://wordpress.org/support/plugin/rocket-lazy-load/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/rocket-lazy-load/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/rocket-lazy-load/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [juslintek](https://wordpress.org/support/users/juslintek/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/bug-with-brackets/#post-10160556)
 * Status: not a support question