[wp-hackers] help understanding wp_remote_get function and fatal WP_Error

The Avanti Group chuck at avantigroup.com
Tue Feb 26 02:07:33 UTC 2013


Hi WP-Hackers ... i'm hoping someone on this list might be able to 
help shed light on why my wp_remote_get function is generating fatal 
errors ...

the php error log says "Cannot use object of type WP_Error as array 
in /mysite/wp-content/themes/mychildtheme/functions.php on line 288" ...

said line 288 is this one -> if ( 200 == $resp['response']['code'] ) {

and my entire function is listed below ... this function is calling a 
text file thus not sure if that is the problem in that wp_remote_get 
only works with html files (e.g., head, title, and body tags) ..??.. 
or if i am missing something more basic (e.g., like a comma between 
['response'] ['code'] or what ..??..

accordingly, thanks in advance for any pointers that can be shared 
... cordially, chuck scott


===============
here is my function that iis responsible for error ->
===============
function myfunkyfunction() {
         $resp = wp_remote_get( 
'http://mydomain.com/dir1/dir2/dir3/my-text-file.txt' );
         if ( 200 == $resp['response']['code'] ) {
                 $body = $resp['body'];
                 }
         else {
                 $body = "Oops - sorry there was a problem loading the stats";
         }
         return $body;
}
add_shortcode('woi102stats','myfunkyfunction');


ps - i'm using latest version of WP 3.5.1 and this function is on a 
sub site on a multisite network - not sure that matters but mention 
just in case ..??..

- fin -



------------------------------------------------------------------------------
Chuck Scott -> Information Architect
------------------------------------------------------------------------------
Specialty -> WordPress Multisite Information Design
------------------------------------------------------------------------------
Site -> http://ChuckingIt.com - Reflecting on Life,
Business, Entrepreneurship, Innovation & Technology
------------------------------------------------------------------------------
What's New -> Tweeting a bit at @avantigroup
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------


More information about the wp-hackers mailing list