herb miller
WordPress plugin specialist
 

H2GD Part 15: broken image in Chrome for JetPack stats

This simple slideshow demonstrates a problem with the JetPack stats plugin which results in a broken image when viewing the site using Chrome. A fix for the problem is provided for Jetpack v1.7

Jetpack stats image NOT YET brokenJetpack stats image now displayed as a broken image

 

Links:

Admin-bar Stats image not showing up

Chrome browser does not show images generated by HTTP handler

 

Download the patch

Attached to this post is the fix for this problem. It’s a patch file for Jetpack version 1.7.

stats.php.patch.0911stats.php.patch.0911

Explanation

  • When the webpage is created Jetpack sets the source for the image in the admin bar as “http://example.com/wp-admin/admin.php?page=stats&noheader&proxy&chart=admin-bar-hours&height=20&hours=48″
  • The browser performs a GET for this image
  • Which sends the message to WordPress admin which invokes the JetPack stats function called stats_reports_page().
  • This then sends a remote request to wordpress.com
  • Which replies with the generated PNG file in the body of the response
  • The Stats function then echo’ed this PNG file to the browser using the following (simplified) code header( "Content-Type: image/png" ); die( $get['body'] )

  • Apparently Google chrome doesn’t care for this ( see the second link )
  • It is happier when the code is changed to header( "Content-Type: image/png" ); $img = $get['body']; header( 'Content-Length: ' . strlen( $img ) ); echo $img; exit();
  • So that’s what the patch file contains

3 Responses to H2GD Part 15: broken image in Chrome for JetPack stats

Contact me
Sorry if the input fields are too wide! You can partially blame Jetpack for creating the unwanted CSS and my plugin's use of a table to display the form.

/* table { table-layout: fixed; } */
.textwidget td input[type=text],
.textwidget td input[type=email],
.textwidget td textarea { width: 100%; }
 
Archives