publish_post срабатывает дважды каждый раз, когда я нажимаю опубликовать или обновить - PullRequest
0 голосов
/ 31 мая 2019

Я хочу, чтобы конвейер bitbucket был запущен после публикации или обновления сообщения.Таким образом, я использовал API конвейера bitbucket в действии publish_post.API конвейера работает нормально.Однако функция publish_post срабатывает дважды каждый раз, когда я нажимаю «Опубликовать или обновить».

Я пытался использовать if ( !wp_is_post_autosave( $ID ) || !wp_is_post_revision( $ID ) ) для указания сообщения, но это не сработало.

Этоэто код, который я использую.

  $ch = curl_init("https://api.bitbucket.org/2.0/repositories/myworkspace/myrepo/pipelines/");

  $userpwd = "username:password";
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json'
  ));
  $vars = json_encode(array(
    "target" => array(
      "ref_type" => "branch", 
      "type" => "pipeline_ref_target", 
      "ref_name" => "develop"
    )
  ));
  curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);
  curl_exec($ch);
  curl_close($ch);
  error_log("rebuild");
}
add_action( 'publish_post', 'rebuild_site', 10, 2 );```

I expect the bitbucket pipeline fires once after publish or update is clicked and the post is saved in Wordpress. However, the pipeline fires twice now and I can see "rebuild" string twice in the error log. Also, the post cannot be save correctly at this time. I got a red bar at the top at the page shows that Update Failed.

Can anybody help me with this? Thanks
...