Integrating Twitter with WordPress
I wanted to integrate Twitter tweets as Asides into another blog I was setting up. The excellent Twitter Tools from alexking.org did exactly what I wanted except that the posts created had comments and trackbacks (pings) open. There was no option to default the comments/trackback status.
I wanted comments and trackbacks for Asides to be closed for now, so a quick hack was in order. I suppose I could have added new options to make this configurable but I was too lazy. :p
- Steps:
- Backup your original copy of twitter-tools.php.
- Open up twitter-tools.php in the plugin editor.
- Look for this snippet
, 'post_status' => 'publish'and add these 2 lines after that. I had to add the lines twice, once for the functiondo_tweet_postand another time for the functiondo_digest_post.
, 'comment_status' => 'closed'
, 'ping_status' => 'closed'
Example for function do_tweet_post (additions at lines 10-11):
-
function do_tweet_post($tweet) {
-
global $wpdb;
-
remove_action(‘publish_post’, ‘aktt_notify_twitter’);
-
‘post_content’ => $wpdb->escape($tweet->tw_text)
-
, ‘post_title’ => $wpdb->escape(trim_add_elipsis($tweet->tw_text, 30))
-
, ‘post_status’ => ‘publish’
-
, ‘comment_status’ => ‘closed’
-
, ‘ping_status’ => ‘closed’
-
);
-
$post_id = wp_insert_post($data);
-
add_post_meta($post_id, ‘aktt_twitter_id’, $tweet->tw_id, true);
-
add_action(‘publish_post’, ‘aktt_notify_twitter’);
-
}
The code is provided as-is, with absolutely no warranties, so please don’t blame me if something disastrous happens. Backup backup backup.
About this entry
You’re currently reading “Integrating Twitter with WordPress”, an entry on dis.content
- Published:
- 08.10.07 / 12pm
- Category:
- Technology
No comments
Jump to comment form | comments rss | trackback uri