Viewing 7 replies - 1 through 7 (of 7 total)
  • The RSS handling that Twitter for WordPress uses was deprecated in WP 3 and isn’t supported in WP 3.1. I’ve managed to get my copy working by changing references to:

    include_once(ABSPATH . WPINC . '/class-simplepie.php');

    to

    include_once(ABSPATH . WPINC . '/rss.php');

    replacing calls to

    fetch_rss()

    with

    fetch_feed()

    and then making some modifications to work with the SimplePie object that’s returned (see http://simplepie.org/wiki/setup/sample_page for an example of SimplePie in action).

    I’ve only changed the pieces I absolutely need and don’t have time right now to produce and submit a complete patch but it shouldn’t take someone who knows the plugin code long to make the necessary changes.

    jystewart – any chance you’d be willing to share the code changes? I looked at it briefly, but if you’ve already done it… 😉

    eric@ericmmartin.com

    Thanks!

    Sure. Sorry to not get back sooner but I was away at SxSW.

    I tried to generate a diff but for some reason I’m getting the entire file as a diff (I may have changed the indentation style or something), so instead here’s my version of the twitter_messages() function, which is the only thing I changed. To update the plugin properly some related changes need to be made elsewhere, and I suspect there’s now some redundant code that should be removed?

    function twitter_messages($username = '', $num = 1, $list = false, $update = true, $linked  = '#', $hyperlinks = true, $twitter_users = true, $encode_utf8 = false) {
    
    	global $twitter_options;
    	include_once(ABSPATH . WPINC . '/class-simplepie.php');
    
    	$messages = fetch_feed('http://twitter.com/statuses/user_timeline/'.$username.'.rss');
    	$items = $messages->get_items();
    	if ($list) echo '<ul class="twitter">';
    
    	if ($username == '') {
    		if ($list) echo '<li>';
    		echo 'RSS not configured';
    		if ($list) echo '</li>';
    	} else {
    			if ( empty($items) ) {
    				if ($list) echo '<li>';
    				echo 'No public Twitter messages.';
    				if ($list) echo '</li>';
    			} else {
            $i = 0;
    				foreach ( $items as $message ) {
    					$msg = " ".substr(strstr($message->get_description(),': '), 2, strlen($message->get_description()))." ";
    					if($encode_utf8) $msg = utf8_encode($msg);
    					$link = $message->get_permalink();
    
    					if ($list) echo '<li class="twitter-item">'; elseif ($num != 1) echo '<p class="twitter-message">';
    
              if ($hyperlinks) { $msg = hyperlinks($msg); }
              if ($twitter_users)  { $msg = twitter_users($msg); }
    
    					if ($linked != '' || $linked != false) {
                if($linked == 'all')  {
                  $msg = '<a href="'.$link.'" class="twitter-link">'.$msg.'</a>';  // Puts a link to the status of each tweet
                } else {
                  $msg = $msg . '<a href="'.$link.'" class="twitter-link">'.$linked.'</a>'; // Puts a link to the status of each tweet
    
                }
              } 
    
              echo $msg;
    
            if($update) {
              $time = strtotime($message['pubdate']);
    
              if ( ( abs( time() - $time) ) < 86400 )
                $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
              else
                $h_time = date(__('Y/m/d'), $time);
    
              echo sprintf( __('%s', 'twitter-for-wordpress'),' <span class="twitter-timestamp"><abbr title="' . date(__('Y/m/d H:i:s'), $time) . '">' . $h_time . '</abbr></span>' );
             }          
    
    					if ($list) echo '</li>'; elseif ($num != 1) echo '</p>';
    
    					$i++;
    					if ( $i >= $num ) break;
    				}
    			}
    		}
    		if ($list) echo '</ul>';
    	}

    Jystewart, thanks for taking the time to get into this problem.
    I am running WP 3.1 as well and now and then also getting the error “No public Twitter messages”. (most of the times not though)
    I changed the code, causing the following n error:
    Fatal error: Cannot use object of type SimplePie_Item as array in (…) twitter.php on line 91

    Surely this plugin must get compatible with WP 3+ ?

    The no public twitter messages issue is mentioned before but never with a real solution (older threads)… Does this have to do with wp 3+?

    Thanks in advance!

    bassoo, you’ve hit on an element of the code I’m not using and so hadn’t updated.

    I don’t have a line 91 in my amended copy, but line 92 is:

    $time = strtotime($message['pubdate']);

    which shows the plugin still using $message as an array rather than the object that it is. I can’t remember how the SimplePie API exposes pubdate (should be easy to find in the docs) but you’ll need that to become something along the lines of:

    $time = strtotime($message->get_pubdate());

    The plugin definitely needs a more thorough overhaul than I’ve had time for. Hopefully the original author could do that? I’m definitely not going to have any time before May.

    ckruse

    (@ckruse)

    I am using the plugin on the latest WP install (3.1.1) The plugin is working fine for me, minus the timestamp. I was able to get the timestamp working by doing the following.

    on line 91/92:
    $time = strtotime($message['pubdate']); //this code still works

    The code following that line is what is not working. I commented everything else out within the if statement

    if($updated) {
    
           $time = strtotime($message['pubdate']);
          /*
           forget the rest
          */
    
    }

    I then added my own echo statement.

    if($updated) {
    
           $time = strtotime($message['pubdate']);
           echo '<span class="timestamp">' . date('m/d/Y H:ia', $time) . '</span>';
          /*
           forget the rest
          */
    
    }

    It is a hack, but it works until the plugin is updated. Hope this helps someone.

    thanks jystewart

    for those using the timestamp you should change the code to:
    $time = strtotime($message->get_date());

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Twitter for WordPress broken on upgrade to 3.1’ is closed to new replies.