
弊社はGoogleChatを使っています。
GoogleChatのwebhookの機能を使って、記事投稿をChatに通知する実装を晒しますね。
function.phpに記載して動かしてます。ご参考にどうぞ。
function update_notify($id,$post){
$result = array();
$webhook_url = "<google chatのwebhook url>";
if(
$post->post_type == "post" &&
$post->post_status == "publish" &&
$post->post_date == $post->post_modified
){
$data = json_encode([
'text' => $post->post_title . "\n" . $post->guid
], JSON_UNESCAPED_UNICODE);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $webhook_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
curl_close($curl);
}
}
add_action('wp_insert_post','update_notify',10,3);
WEB制作・ITに関するお悩みや
ご質問等お気軽にご相談ください
