• I’ve started using this plugin to lazy load images, including a custom method my theme uses for featured images. I noticed this issue on an article that doesn’t have a featured image at all, but I think the issue might occur in other situations as well.

    In /wp-content/plugins/easy-lazy-loader/easy-lazy-loader.php on line 652, I get the error that placeholder_color is undefined.

    Here’s how the code appears to be working:

    
    // use low res preview image as placeholder if applicable
    if ( 'lowres' === $placeholder_type && $img_id !== false ) {
    	$tiny_img_data  = wp_get_attachment_image_src( $img_id, $this->OPTIONS['placeholder_image_size'] );
    	$tiny_url = $tiny_img_data[0];
    	$placeholder_url_used = $tiny_url;
    }
    // use color as placeholder if applicable
    else if ( 'color' === $placeholder_type && class_exists( 'WordPress_Gallery_Extra' ) ) {
    	$placeholder_color = "";
    
    	if( $img_id !== false ) {
    		$placeholder_color = get_post_meta( $img_id, '_wgextra_dominant_color', true );
    	}
    
    	if ( !$placeholder_color ) {
    		$placeholder_color = $this->OPTIONS['default_image_placeholder_color'];
    	}
    
    	$placeholder_url_used = self::create_placeholder( $placeholder_color, (int) $width, (int) $height, 'Image loading...' );
    }
    // use transparent as placeholder if applicable
    else if ( 'default' === $placeholder_type && !is_string( $width ) && !is_string( $height ) ) {
    	$placeholder_url_used = self::create_placeholder( $placeholder_color, (int) $width, (int) $height );
    }
    

    If I understand correctly, placeholder_color is only defined if WordPress_Gallery_Extra exists, but even if it does not exist, the plugin attempts to use it:

    
    // use transparent as placeholder if applicable
    else if ( 'default' === $placeholder_type && !is_string( $width ) && !is_string( $height ) ) {
    	$placeholder_url_used = self::create_placeholder( $placeholder_color, (int) $width, (int) $height );
    }
    

    It doesn’t seem like anything is keeping this placeholder method from being called, while looking for a color value that may not exist.

  • The topic ‘Undefined variable: placeholder_color’ is closed to new replies.