Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Updating class-snoopy.php widget to http.php WordPress

  • SOLVED

I have a twitter widget that uses class-snoopy.php which is now deprecated and I receive this message:

<blockquote>Notice: class-snoopy.php is deprecated since version 3.0! Use wp-includes/http.php instead.</blockquote>

So, I have updated the include to include http.php instead but I then get the error of:

<blockquote>Fatal error: Class 'Snoopy' not found in /home/path/to/backend/widgets/twitter.php on line 28</blockquote>

So, here is the area of code affected:

if ($tweet['lastcheck'] < (mktime() - 60)) {
$snoopy = new Snoopy;
$result = $snoopy->fetch($url);

// Check if any tweets were returned from Twitter API
if ($result) {
$twitterdata = json_decode($snoopy->results, true);


Line 28:

$snoopy = new Snoopy;

Obviously I'm using snoopy to fetch the tweets but since it is now changed to use http.php, I need to update this, but what to?

Answers (2)

2011-03-28

Lew Ayotte answers:

since class Snoopy is deprecated and you should use WP Http, you won't be able to do a 'new Snoopy' without including the snoopy class. You need to do a "new WP_Http"...

Here is a good blog post about using the WP Http API - [[LINK href="http://planetozh.com/blog/2009/08/how-to-make-http-requests-with-wordpress/"]]http://planetozh.com/blog/2009/08/how-to-make-http-requests-with-wordpress/[[/LINK]]

2011-03-28

yves vu answers:

Hi,

WordPress 3.x update: you now need to explicitly include the class if you intend to use it, that is start by adding the following lines:

Please follow 2 steps:
Step1: if you don't include,please add code
if( !class_exists( 'WP_Http' ) )
include_once( ABSPATH . WPINC. '/class-http.php' );


Step2:
Change this code:
if ($tweet['lastcheck'] < (mktime() - 60)) {

$snoopy = new Snoopy;

$result = $snoopy->fetch($url);



// Check if any tweets were returned from Twitter API

if ($result) {

$twitterdata = json_decode($snoopy->results, true);


To code:
$request = new WP_Http;
$result = $request->request($url);
// Check if any tweets were returned from Twitter API

if ($result) {

$twitterdata = json_decode($result['body'], true);


If this solutions is not ok .
Please send email to me: [email protected]

Cheers.