• Hey Guys,

    I just threw together my first plugin. I am using Twitter Tools to pull in a Twitter feed into WordPress. It was perfect for my needs except for one thing – I wanted Twitpic URL’s to display as an image instead of the link URL. I mostly borrowed code from different places, but it works. I am posting it here just in case it helps someone. If anyone wants to improve the code I would be super grateful! (I am not a programmer, so please excuse any obvious mistakes)

    Cheers

    <?php
    /*
    Plugin Name: Twitpic Expander
    Plugin URI: http://jacksonlaycock.com/
    Description: Scans posts for twitpic URL's and automatically expands them and shows an image.
    Version: 1.0
    Author: Jackson Laycock
    Author URI: http://jacksonlaycock.com/
    */
    ?>
    <?php
    // borrowed code from http://code.google.com/p/dabr/source/browse/trunk/common/twitter.php?spec=svn116&r=116
    
    function showtwitpic($text){
    	$foo = $text;
    	$tmp = strip_tags($text);
    	// find a mention of twitpic
    	if (preg_match_all('#twitpic.com/([\d\w]+)#', $tmp, $matches, PREG_PATTERN_ORDER) > 0) {
    		foreach ($matches[1] as $match) {
    	     $text = "<a href='http://twitpic.com/{$match}'><img src='http://twitpic.com/show/large/{$match}' class='aligncenter' /></a>";
    	  	}
    		$text = $foo . $text;
    	}	
    
    	return 	$text;
    }		
    
    add_filter('the_content', 'showtwitpic', 21);
    add_filter('the_excerpt', 'showtwitpic', 21);
    ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Pretty cool, you should make this a plugin for Twitter Tools so it works in the sidebar too.

    Thread Starter bh

    (@bh)

    Thanks Alex. I would love to, but I might have to pass the torch on this one.

    Thanks again for such a great WP/Twitter Plugin!

    Thanks, this is just what I’m looking for though for some reason, if a post has more than one twitpic link, only the last one gets its picture displayed. I’ll try to see if I can figure this out.

    Thanks for the code!

    Thread Starter bh

    (@bh)

    Hey Vuthy,
    Did you figure out the code and make any changes?

    To fix the “more than one twitpic per twit” problem, you just need to concatenate the images together with a .= (on the $images = line):

    <?php
    function showtwitpic($text){
      $foo = $text;
      $tmp = strip_tags($text);
    
      // find a mention of twitpic
      if (preg_match_all('#twitpic.com/([\d\w]+)#', $tmp, $matches, PREG_PATTERN_ORDER) > 0) {
        foreach ($matches[1] as $match) {
          $images .= "<a href='http://twitpic.com/{$match}'><img src='http://twitpic.com/show/thumb/{$match}' class='aligncenter' /></a>";
        }
        $text = $foo . '<center>' . $images . '</center>';
      }
    
      return $text;
    }
    
    add_filter('the_content', 'showtwitpic', 21);
    add_filter('the_excerpt', 'showtwitpic', 21);
    ?>
    Thread Starter bh

    (@bh)

    Finally got around to adding this to the plugin directory.

    http://wordpress.org/extend/plugins/twitpic-expander/

    I also included Smoovej’s change above (thanks!).

    paulstenhouse

    (@paulstenhouse)

    When this plugin is active, I am getting an error when I try to logout.

    I get a whole page of errors that look like this:

    Warning: Cannot modify header information – headers already sent by (output started at /home/ilovene/public_html/paulstenhouse.com/wp-content/plugins/twitpic-expander/twitpic-expander.php:14) in /home/ilovene/public_html/paulstenhouse.com/wp-login.php on line 302

    Warning: Cannot modify header information – headers already sent by (output started at /home/ilovene/public_html/paulstenhouse.com/wp-content/plugins/twitpic-expander/twitpic-expander.php:14) in /home/ilovene/public_html/paulstenhouse.com/wp-login.php on line 314

    Warning: Cannot modify header information – headers already sent by (output started at /home/ilovene/public_html/paulstenhouse.com/wp-content/plugins/twitpic-expander/twitpic-expander.php:14) in /home/ilovene/public_html/paulstenhouse.com/wp-includes/pluggable.php on line 692

    Warning: Cannot modify header information – headers already sent by (output started at /home/ilovene/public_html/paulstenhouse.com/wp-content/plugins/twitpic-expander/twitpic-expander.php:14) in /home/ilovene/public_html/paulstenhouse.com/wp-includes/pluggable.php on line 693

    And it means I can’t log out..

    How can I fix this because it is a great plugin!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Plugin: Twitpic Expander’ is closed to new replies.