Replace this line:
if ($old_status != 'draft' || $new_status != 'publish') {
with:
if ( $post->post_type != 'post' || $new_status != 'publish' || $old_status != 'auto-draft' ) {
You want to run your code on post
transition from auto-draft
to publish
, which will occur once only, when your post
is created.
UPDATE
The problem is in this part of your code:
$resp = curl_exec($curl);
error_log(" [ ". date("Y-m-d H:i:s") . " ] sending post with ID = ". $post_ID ."\n", 3, $_SERVER['DOCUMENT_ROOT'] . "/log.txt");
if (!curl_exec($curl)) {
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
You are calling curl_exec($curl)
in two lines! First:
$resp = curl_exec($curl);
and second:
if (!curl_exec($curl)) {
Change your if
statement to:
if (!$resp) {