Twitpress - wordpress plugin for twitter
Twitterpress is a simple plugin to update your twitter account automatically whenever you publish a new post from your hosted wordpress blog. It makes use of the Twitter API developed by Nick Beam. This is actually a geek friendly version which will require one to write a little something in my code to get to work for you. may be a v1.01 sometime to make an admin panel for it.
To install
1. download and unzip the twitterpress.zip into your wp-content/plugins folder
2. activate the plugin via your plugins tab
3. in the twitpress folder update the twitpress.php file with your username and password.
Thats it. Whenever you publish a post on your hosted wordpress blog, it will automatically update your status on twitter with a link to your latest blog. Neat for people who have a lot of followers and would like to inform them about their latest post. In this way its a sort of a real time RSS over gtalk.
Lets do a little dissection of the twitpress.php file. You would see something like
add_action ('publish_post', 'update_status'); //adding an action
This is what we call a wordpress hook. It tells the core that whenever an action of publish post happens, call a function called update_status.
The function update_status makes use of the twitter API. Takes the post_ID as the argument and from that extracts the title and permalink from it and makes a status message.
It then creates an object of twitter class and calls its updateStatus function. It then ends the session and like all good hook functions returns the post_ID.
function update_status($post_ID) {
$username = "XXXXXXX"; //Your twitter username here
$password = "XXXXXXX"; //Your twitter password here
$status_start = "Hey, check out our new post " ; //what would you like to see before your status message
$post_title = $_POST['post_title'];
$post_url = get_permalink($post_ID);
$status = $status_start . " - " . $post_title . " @ " . $post_url ; //read the title and url
$twitter = new Twitter($username,$password);
$twitter->updateStatus($status);
$twitter->endSession();
return $post_ID;
}
Easy peasy lemoneasy. Feel free to share. Download the twitpress plugin here.


1 Bahs !:
neat. May be in-depth tutorial into the twitter api next.
Post a Comment