wordpress评论微信通知

wordpress网站可以通过邮箱来通知网站新评论,可是我们可能不会一直盯着邮箱看有没有新信息,使用本文方法即可让wordpress新评论实现微信通知

图片[1]-wordpress评论微信通知-凡星爱分享

1.注册Server酱,获取Sendkey
实际上不是注册,就是微信扫一下就可以了,自己百度搜索一下吧。

图片[2]-wordpress评论微信通知-凡星爱分享

2.functions.php放入以下代码
在主题函数文件functions.php代码中放入以下代码,并将你的sendkey填入代码中对应的位置

//博客评论消息微信推送
function sc_send($comment_id)
{
$text = '博客上有一条新的评论';
$comment = get_comment($comment_id);
$desp = $comment->comment_content;
$key = '这里填你的SendKey';
$postdata = http_build_query(
array(
'text' => $text,
'desp' => $desp
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
return $result = file_get_contents('https://sctapi.ftqq.com/'.$key.'.send', false, $context);
}
add_action('comment_post', 'sc_send', 19, 2);

大功告成,不过免费版Server酱只提供每天5条消息的微信通知,尝尝新鲜是非常不错的,评论比较多的还是放弃吧。

图片[3]-wordpress评论微信通知-凡星爱分享
© 版权声明
THE END
喜欢就支持一下吧
点赞134 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容