Created
April 16, 2014 14:06
-
-
Save ccbikai/10881201 to your computer and use it in GitHub Desktop.
利用pushbullent推送wordpress评论
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pushbullet($title,$body) | |
{ | |
$apikey='v1dFWupd5ifoOz0tajOc'; | |
$device_iden='ujEH7v8iCkedjz'; | |
$req_args = array( | |
'headers' => array( | |
'Authorization' => 'Basic ' . base64_encode( $apikey.':') | |
), | |
'timeout' => 50, | |
'sslverify' =>FALSE, | |
'method' => 'post', | |
'body'=>array( | |
'type' => 'note', | |
'device_iden'=>$device_iden, | |
'title' => $title, | |
'body'=>$body) | |
); | |
$response = wp_remote_post( 'https://api.pushbullet.com/api/pushes', $req_args ); | |
} | |
function miantiao_push($comment_ID) | |
{ | |
$comment = get_comment($comment_ID); | |
if (empty($comment)) | |
{ | |
return; | |
} | |
if ($comment->comment_approved != 'spam') | |
{ | |
$post = get_post($comment->comment_post_ID); | |
if ($comment->user_id == $post->post_author) | |
{ | |
return; | |
} | |
if ('pingback' == $comment->comment_type || 'trackback' == $comment->comment_type) | |
{ | |
return; | |
} | |
$title = $comment->comment_author . " 评论了 《" . get_the_title($comment->comment_post_ID) . "》"; | |
$body = "文章:《" . get_the_title($comment->comment_post_ID) . "》\n评论: " . trim($comment->comment_content) . "\n链接: " . get_permalink($comment->comment_post_ID) . '#comment-' . $comment_ID; | |
pushbullet($title,$body); | |
} | |
} | |
add_action('comment_post', 'miantiao_push', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment