我想在发布或更新帖子后启动Bitbucket管道。因此,我在publish_post操作中使用了bitbucket管道API。管道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