I am making a very simple plugin to contact OneSignal, a service to send notifications to an android app, when a post is published.
This plugin have no interface, only when a post is published by an admin is called but there are my API Keys of OneSignal showed.
function sendMessage($postTitle, $postLink)
{
$heading = array(
"en" => "New post!");
$content = array(
"en" => $postTitle);
$fields = array(
'app_id' => "MY API KEY",
'included_segments' => array('All'), 'data' => array("postLink" => "$postLink"), 'contents' => $content, 'headings' => $heading);
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic MY SECOND API KEY'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
As you can see the API KEY are in clear.
I should hide this keys in some way? If yes, how? Please keep in mind this is my first time I “develop” something in WordPress so maybe I make something wrong.
Thank you!