getTimestamp(); $final_date = $notify_time; $final_readable_date = date('Y-m-d h:i:00a', $final_date); $content = array( "en" => $notify_message ); $title = array( "en" => $notify_title ); if ($selected_method == "send-scheduled") { $body = new stdClass(); $body->app_id = $OneSignalWPSetting_app_id; $body->contents = $content; $body->headings = $title; $body->url = $notify_url; $body->send_after = $final_readable_date; $body->included_segments = array('All'); $bodyAsJson = json_encode($body); } else { $body = new stdClass(); $body->app_id = $OneSignalWPSetting_app_id; $body->contents = $content; $body->headings = $title; $body->url = $notify_url; $body->included_segments = array('All'); $bodyAsJson = json_encode($body); } $response = wp_remote_post("https://onesignal.com/api/v1/notifications", array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array("Content-type" => "application/json;charset=UTF-8", "Authorization" => "Basic " . $OneSignalWPSetting_rest_api_key), 'body' => $bodyAsJson, ) ); // echo $response["body"]; if ($selected_method == "send-scheduled") { $result['msgstatus'] = "Scheduled"; } else { $result['msgstatus'] = "Sent"; } $result['type'] = "success"; $result['api_response'] = $response["body"]; } else { $result['type'] = "error"; } if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $result = json_encode($result); echo $result; } else { header("Location: " . $_SERVER["HTTP_REFERER"]); } die(); }