我是WordPress的新手。帖子状态更改时,我想调用外部API。
文件:wp-includes \ functions.php
$EXTERNAL_ADD_INDEX_API = 'api end point'
function wpdocs_run_on_publish_only( $new_status, $old_status, $post ) {
$ch = curl_init($EXTERNAL_ADD_INDEX_API . "?postId=" . $post->ID);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
}
add_action( 'transition_post_status', 'wpdocs_run_on_publish_only', 10, 3 );
问题:发布/删除帖子时未调用wpdocs_run_on_publish_only函数(->未调用api)。