Created
September 17, 2010 23:52
-
-
Save mattrude/585160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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