通过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);