【发布时间】:2019-01-06 06:50:04
【问题描述】:
我有这个通知功能,需要在代码的不同地方调用。我需要把它放在我的子主题以及插件目录中的任何文件都可以访问的地方。
function send_notification($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = My_Token',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
- 第一个问题,放在哪里,目前在functions.php中?
- 第二个问题,不同地方怎么称呼?
任何解决方案和参考将不胜感激。谢谢。
【问题讨论】:
标签: wordpress function notifications call