Skip to content

Instantly share code, notes, and snippets.

@mattrude
Created September 17, 2010 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrude/585160 to your computer and use it in GitHub Desktop.
Save mattrude/585160 to your computer and use it in GitHub Desktop.
<?php
function twitter_import() {
require "twitter.lib.php";
$username = "mdrude";
$password = "<password>";
$twitter = new Twitter($username, $password);
$old_id = get_option('milly_twitter_old_id');
$xml = $twitter->getUserTimeline("max_id=$old_id");
$twitter_status = new SimpleXMLElement($xml);
global $user_ID;
foreach($twitter_status->status as $status){
if ( $status->id > $old_id ) {
echo "running";
$tweet_text = $status->text;
$created_at = $status->created_at;
$tweet_date = date("Y-m-d H:i:s", strtotime($created_at));
$tweet_id = $status->id;
$new_post = array(
'post_title' => $tweet_text,
'post_content' => $tweet_text,
'post_status' => 'publish',
'post_date_gmt' => $tweet_date,
'post_author' => $user_ID,
'post_type' => 'twitter'
);
$post_id = wp_insert_post($new_post);
add_post_meta($post_id, 'aktt_twitter_id', "$tweet_id");
add_post_meta($post_id, 'twitter_id', "$tweet_id");
update_option('milly_twitter_old_id', "$tweet_id");
}
}
}
add_filter('cron_schedules', 'cron_add_milly');
function cron_add_milly( $schedules )
{
$schedules['milly'] = array(
'interval' => 300,
'display' => __('Every 5 Mins')
); return $schedules;}
if (!wp_next_scheduled('twitter_import_hook')) {
echo "Updating schedule";
wp_schedule_event( time(), 'milly', 'twitter_import_hook' );
}
add_action( 'twitter_import_hook', 'twitter_import' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment