首页 > 其他分享 >wordpress新增文章新增评论自动通知到微信

wordpress新增文章新增评论自动通知到微信

时间:2024-09-08 23:20:57浏览次数:6  
标签:comment pushhub title 微信 新增 content wordpress post ID

研究了下,如何让wordpress新增文章或者新增评论的时候通知到微信。

复制下方代码,粘贴到主题的functions.php文件中即可

在wordpress6.6.1版本测试通过
理论上支持5.0以上的wp,有问题可以留言反馈

/*
在pushhub个人中心复制你的token,填入下方
获取token:https://www.pushhub.cn/user
*/
add_action('wp_insert_comment', 'pushhub_comment', 10, 2);
add_action('wp_insert_post', 'pushhub_post', 10, 3);
function pushhub($title,$content){
    $url = 'https://api.pushhub.cn/send';
    $data = array(
        'token' => 'xxxxxxxxx',  //【这里填你的token】
        'title' => $title,
        'content' => $content
    );
    wp_remote_post($url, array(
        'body' => json_encode($data),
        'headers' => array('Content-Type' => 'application/json')
    ));
}
function pushhub_comment($comment_ID, $comment_approved) {
    // 检查评论是否已经通过审核
    if ($comment_approved != 1) {
        return;
    }
    $comment = get_comment($comment_ID);
    $post = get_post($comment->comment_post_ID);
    $post_title = get_post($comment->comment_post_ID)->post_title;
    $conmment_link = get_comment_link($comment_ID);
    $conment_date = $comment->comment_date;
    $content="《 ".$post_title." 》有一条新评论:\n\n".$comment->comment_content."\n\n\n评论时间:$conment_date\n评论链接:<a href='$conmment_link'>$conmment_link</a>";
    pushhub('新评论:'.$comment->comment_content,$content);
}
function pushhub_post($post_ID, $post, $update) {
    // 检查是否为新文章而不是更新文章,如果更新文章也要通知,可以把这个去除掉
    if ($update) {
        return;
    }
    if(in_array($post->post_title,array('自动草稿','Custom Styles'))){
        return;
    }
    $post_url = get_permalink($post_ID);
    $content = "新增文章:《".$post->post_title."》\n------------------\n文章链接:<a href='$post_url'>$post_url</a>";
    pushhub('新文章:'.$post->post_title,$content);
}

效果如下:

也可以推松通知到钉钉、飞书、发邮件,在pushhub设置一下就行。

标签:comment,pushhub,title,微信,新增,content,wordpress,post,ID
From: https://blog.csdn.net/qq_43012108/article/details/142035193

相关文章

  • 微信小程序 云数据库 Collection/Query .orderBy 用法
    Collection.orderBy/Query.orderBy指定查询排序条件方法签名如下:functionorderBy(fieldName:string,order:string):Collection|Query方法接受一个必填字符串参数fieldName用于定义需要排序的字段,一个字符串参数order定义排序顺序。order只能取asc或desc。如果需要......
  • 微信小程序报错:Component is not found in path "components/comp/comp.js"
    完整错误jsEnginScriptError:Componentisnotfoundinpath"components/comp/comp.js"(usingbypages/index/index);onAppRouteError:Componentisnotfoundinpath"components/comp/comp.js"(usingbypages/index/index) ine(...) ...错误......
  • 为什么微信小程序设置的onPullDownRefresh无效
    因为仅有onPullDownRefresh是不行的,需要配置:如果是单个页面需要onPullDownRefresh,在对应页面的json文件中设置"enablePullDownRefresh":true,如:{"backgroundTextStyle":"light","navigationBarBackgroundColor":"#fff","navigation......
  • 微信小程序 云数据库 Collection/Query .orderBy 用法
    Collection.orderBy/Query.orderBy指定查询排序条件方法签名如下:functionorderBy(fieldName:string,order:string):Collection|Query方法接受一个必填字符串参数fieldName用于定义需要排序的字段,一个字符串参数order定义排序顺序。order只能取asc或desc。如果需要......
  • 微信小程序报错:Component is not found in path "components/comp/comp.js"
    完整错误jsEnginScriptError:Componentisnotfoundinpath"components/comp/comp.js"(usingbypages/index/index);onAppRouteError:Componentisnotfoundinpath"components/comp/comp.js"(usingbypages/index/index) ine(...) ...错误......
  • WordPress在文章内容中对文字加模糊隐藏效果
    WordPress在文章内容中对文字加模糊隐藏效果,你可以放一些提取码,或者提示信息,甚至是一些秘密。。。实现也很简单,单纯css就可以了。教程开始:首先来到后台=>外观=>自定义=>额外CSS如图:将以下CSS代码加进去:.wponss{text-decoration:none;transition:filt......
  • 在微信小程序中做自己的数字键盘
    为什么要自制键盘?我最近在开发一款微信小程序,现在需要用户输入一个数字。使用系统键盘带来的不便如果使用系统键盘,有以下几个问题:数字键太小,不方便;无法阻止用户输入不合法字符(如:“&”);小数点在一些手机上很难找到;用户需要点击输入框;无法控制按钮样式。理想的自制键盘效......
  • 使用微信小程序-云开发时报错: Error: errCode: -401003 api parameter type error |
    错误Uncaught(inpromise)thirdScriptErrorerrCode:-401003apiparametertypeerror|errMsg:parameter.datashouldbeobjectinsteadofundefined;Error:errCode:-401003apiparametertypeerror|errMsg:parameter.datashouldbeobjectinsteadofundef......
  • LiteSpeed Cache 漏洞导致 600 万个 WordPress 网站遭受管理员接管
    LiteSpeedCache插件中存在一个严重的帐户接管漏洞,影响了超过600万个WordPress网站,该漏洞已于昨天通过6.5.0.1版发布进行修复。该漏洞允许未经身份验证的用户利用调试日志缺陷接管已登录的帐户,包括具有管理员权限的帐户。Patchstack的安全研究员RafieMuhammad在......
  • 基于python+flask框架的基于微信小程序的二手电商平台设计与实现(开题+程序+论文) 计算
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容研究背景随着互联网技术的飞速发展,电子商务已成为人们日常生活中不可或缺的一部分。在高校校园内,学生群体对二手商品交易的需求日益增长,但传统的线......