Saved tweet!

Add another one

Add Tweet



|$tweet_id|", "Invalid tweet ID"); exit(1); } // https://dev.twitter.com/docs/api/1/get/statuses/show/%3Aid $api_url = "http://api.twitter.com/1/statuses/show/$tweet_id.json"; $request = wp_remote_get($api_url); if (is_wp_error($request)) { wp_die("Unable to fetch data from Twitter : " . $request->get_error_message()); exit(1); } $response = json_decode($request['body']); if (json_last_error() !== JSON_ERROR_NONE) { wp_die("Unable to decode JSON :
 " . var_export($request['body'], true) . "
"); exit(1); } $replies = array( (object) array( 'from_user_id' => $response->user->id, 'from_user' => '@' . $response->user->screen_name, 'profile_image_url' => $response->user->profile_image_url, 'id' => $response->id, 'text' => $response->text, 'created_at' => $response->created_at, 'tweet_url' => $url, ) ); save_replies($post_id, $replies); } function save_replies($post_id, array $replies) { foreach($replies as $reply) { // TODO Replace t.co urls with entities/urls/expanded_url using entities/urls/indices in the JSON $commentdata = array( 'comment_post_ID' => $post_id, 'comment_type' => 'comment', 'comment_author' => $reply->from_user, 'comment_author_email' => 'twitter.' . $reply->id . '@example.com', 'comment_author_url' => $reply->tweet_url, 'comment_content' => $reply->text, 'comment_date' => gmdate('Y-m-d H:i:s', strtotime($reply->created_at)), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', strtotime($reply->created_at)), 'comment_author_IP' => $_SERVER['SERVER_ADDR'], 'comment_agent' => 'Add Tweet as Comment Wordpress Plugin' ); $commentdata['comment_approved'] = wp_allow_comment($commentdata); $comment_id = wp_insert_comment($commentdata); update_comment_meta($comment_id, 'add_tweet_as_comment_account_id', $reply->from_user_id); update_comment_meta($comment_id, 'add_tweet_as_comment_profile_image_url', $reply->profile_image_url); update_comment_meta($comment_id, 'add_tweet_as_comment_status_id', $reply->id); if ('spam' !== $commentdata['comment_approved']) { if ('0' == $commentdata['comment_approved']) { wp_notify_moderator($comment_id); } } $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment if (get_option('comments_notify') and $commentdata['comment_approved'] and (!isset($commentdata['user_id']) or $post->post_author != $commentdata['user_id'])) { wp_notify_postauthor($commentid, isset($commentdata['comment_type']) ? $commentdata['comment_type'] : ''); } } } ?>