From 17d0f894f2c10c636b108f02fad76e33f9160c6a Mon Sep 17 00:00:00 2001 From: EasyChen Date: Sun, 30 Jan 2022 21:01:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0wordpress=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.php | 1 + .../pushdeer.php | 149 ++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 pulgins/wordpress/pushdeer_wordpress_comment_notice/index.php create mode 100644 pulgins/wordpress/pushdeer_wordpress_comment_notice/pushdeer.php diff --git a/pulgins/wordpress/pushdeer_wordpress_comment_notice/index.php b/pulgins/wordpress/pushdeer_wordpress_comment_notice/index.php new file mode 100644 index 0000000..e71af0e --- /dev/null +++ b/pulgins/wordpress/pushdeer_wordpress_comment_notice/index.php @@ -0,0 +1 @@ +通过PushDeer向手机发送通知

"; +} + +function ftqq_pushdeer_settings_is_on_cb() +{ + $setting = get_option('ftqq_pushdeer_settings'); + + $html = ''; + + echo $html; +} + +function ftqq_pushdeer_settings_pushkey_cb() +{ + $setting = get_option('ftqq_pushdeer_settings'); + // 输出字段?> +> +'; + + echo $html; +} + + /** + * 注册 wporg_settings_init 到 admin_init Action 钩子 + */ + add_action('admin_init', 'ftqq_pushdeer_settings_init'); + + function ftqq_pushdeer_comment_send($comment_id) + { + // 读取配置 + $setting = get_option('ftqq_pushdeer_settings'); + // 检查配置 + if (intval(@$setting['is_on']) != 1) { + return false; + } + if (!isset($setting['pushkey']) || strtoupper(substr($setting['pushkey'], 0, 3)) != 'PDU') { + return false; + } + + $comment = get_comment($comment_id); + + // 配置开关:如果文章作者就是评论作者,那么不发送评论 + if (intval(@$setting['author_not_send']) == 1 && (get_post($comment->comment_post_ID)->post_author == $comment->user_id)) { + return false; + } + + $text = '博客['.get_bloginfo('name').']有新的留言'; + $desp = $comment->comment_content ."\r\n\r\n" .'[去博客查看]('.site_url().'/?page_id='.$comment->comment_post_ID.') '; + + $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://api2.pushdeer.com/message/push?type=markdown&pushkey='.$setting['pushkey'], false, $context); + } +add_action('comment_post', 'ftqq_pushdeer_comment_send', 19, 2);