Skip to content

Instantly share code, notes, and snippets.

@ccbikai
Created April 16, 2014 14:06
Show Gist options
  • Save ccbikai/10881201 to your computer and use it in GitHub Desktop.
Save ccbikai/10881201 to your computer and use it in GitHub Desktop.
利用pushbullent推送wordpress评论
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