Im trying to build a function which grabs the feedburner "readers" using wp_remote_get(). I noticed that it frequently returned a value of 0.

I assumed at first that it was a WordPress error (handled by is_wp_error()) or a flaw with wp_remote_get(). Wrong of-course..

Feedburner just kept crashing, so I used a second transient to store a result (never 0) with an expiration of 7 days. The part which i cant get my head around is handling errors with is_wp_error(). I need to force an error so i can handle it properly, before I put it up on production.

Heres an illustration:

$result = wp_remote_get( 'http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=' . urlencode($username) );

if ( is_wp_error($result) )
    return false;

Whats the best way to force an error? Should i use new WP_error()?

2 Answers 2


WordPress can be inconsistent as to when is returns a WP_Error object and when it just returns false or string(0) when actually there was an error. I am not sure exactly what feedburner is returning that is not triggering a WP_Error from wp_remote_get() - but if you know wp_remote_get() will return an WP_Error, I would just set $result = new WP_Error( 'my-error' ); This is the same object that wp_remote_get() will return on error.

  • I haven't encountered an instance where wp_remote_get() triggers a wp_error so im not sure if that's the case. But i wanted to create some sort of fallback in case it does. Ill use your suggestions and see what it gives me. Thanks Joe.
    – VicePrez
    Commented May 20, 2011 at 9:44
  • I just wanted to thank you again. It worked great. Thanks for looking out +1
    – VicePrez
    Commented May 20, 2011 at 19:59

To grab Feedburner stats, I've always used wp_cache_get. Here's a function I've had success with

function get_feedburner_stats() {
  $fbrefreshtime = 43200;  //Refresh Feedburner twice in a day

  $fb = wp_cache_get('fbstats_key');

  if ($fb == false) {
    $yourfeeduri = 'YOUR_FEEDBURNER_USERID'; 
    $feed = 'https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri='.$yourfeeduri;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $feed);
    $feed = curl_exec($ch); curl_close($ch);
    $xml = new SimpleXMLElement($feed);
    $fb = $xml->feed->entry['circulation']; 

    //Set the Value in Cache
    wp_cache_set('fbstats_key', strval($fb), '', $fbrefreshtime);
  return $fb;

To return the value, I use this

<?php echo get_feedburner_stats(); ?>

That being said, Feedburner is horribly unreliable. What I'd recommend doing is building in a conditional that if the number = 0, then it returns a static number.

  • 1
    great suggestion, but I'm looking to trigger a wp_error, not recreate the entire function using cURL let alone use wp_cache_get(). The WordPress codex even suggests staying away from them and use the Transients API instead
    – VicePrez
    Commented May 20, 2011 at 10:04
  • +1 @VicePrez. @Norcross, nice suggestion, but stick to standards and use the available API/wrappers, namely the already mentioned Transients as well as HTTP - codex.wordpress.org/HTTP_API Commented May 20, 2011 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.