【问题标题】:Tweet when comment is created with wordpress使用 wordpress 创建评论时的推文
【发布时间】:2023-03-03 11:09:01
【问题描述】:

我正在使用 wp-twitter 插件(使用 WordPress 3.0.1)在创建帖子时自动创建推文,效果很好!

现在我需要在创建评论时创建推文……你知道有什么插件可以做到吗?

或者,如果您更改了 wp-twitter 插件来做到这一点,请给我一些指导?

提前致谢!

【问题讨论】:

    标签: wordpress twitter tweets


    【解决方案1】:

    您可以使用 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多