上一篇《腾讯云下wordpress发邮件慢的1个搞定方式》,jevin 说太庞大,使用wp的邮件系统老是会有各类问题需要折腾。
因而介绍1个新的告知方式,比邮件费心,速率还快。使用 Server酱 给博主发送微信告知讯息。
关于Server酱,其主页已经有详细的介绍,伏笔VPS总结一下:
接收者使用微信关注公众号并绑定,通过其供给的API,完成发送微信的模板讯息(告知讯息)
关注绑定的方式就不多说了。开始增加到WP:
以下代码插入到正题functions.php任性位置便可
function sendFTQQ($comment_ID,$comment_approved){
//断定讨论能否为渣滓讨论
if( 1 === $comment_approved){
$comment = get_comment($comment_ID);
//断定讨论者email能否是管理员email,如果是,则不发送告知
if($comment->comment_author_email != get_bloginfo ('admin_email')){
$author=$comment->comment_author;
$content=$comment->comment_content;
$comment = $author.':'.$content.'';
$SCKEY = "你申请到的Server酱KEY";
$url = 'https://sc.ftqq.com/'.$SCKEY.'.send?desp='.urlencode($comment).'&text='.urlencode("博客新讨论告知");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION , CURL_SSLVERSION_DEFAULT);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch);
curl_close($ch);
return;
}
}
}
add_action( 'comment_post', 'sendFTQQ', 10, 2 );
注:就中curl能使用file_get_contents代替,只不过本文给出的函数将curl超时设置为1秒
这样做就算Server酱服务器出现问题,从前台提交新讨论的时候仍旧不会卡住影响体会
原文链接:https://host.fubi.hk/foreshadowinghost/zhishiku/20181025/8385.html