我正在使用 wp-twitter 插件(使用 WordPress 3.0.1)在创建帖子时自动创建推文,效果很好!
现在我需要在创建评论时创建推文……你知道有什么插件可以做到这一点吗?
甚至,如果您更改了 wp-twitter 插件来做到这一点,请给我一些指导?
提前致谢!
您可以使用comment_post
钩子并添加将内容提交到您的 Twitter 帐户的操作。
例子:
function tweet_comment($comment_ID, $approved) {
if($approved) {
$comment = get_comment($comment_ID);
//Submit to twitter => $comment->comment_content
$consumerKey = '<insert your consumer key';
$consumerSecret = '<insert your consumer secret>';
$oAuthToken = '<insert your access token>';
$oAuthSecret = '<insert your token secret>';
require_once('<insert_path_to_twitteroauth>/twitteroauth.php');
// create a new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
//send a tweet
$tweet->post('statuses/update', array('status' => substr($comment->comment_content, 0, 140)));
}
}
add_action('comment_post','tweet_comment', 10, 2);