使用HTTP API 要在上发送“ping”wp_insert_post
操作,在创建/更新帖子时激发:
/**
* @param int $post_id The ID of the post.
* @param WP_Post $post The post object.
* @param bool $update True if the post already exists and is being updated
*/
function wpse_185340_post_ping( $post_id, $post, $update ) {
if ( $post->post_status === \'publish\' ) { // Only fire when published
wp_remote_post(
\'http://example.com/application/notify\',
array(
// https://codex.wordpress.org/HTTP_API
\'blocking\' => false, // If you don\'t need to know the response, disable blocking for an "async" request
\'body\' => array(
\'post_id\' => $post_id,
\'post\' => json_encode( $post ),
\'update\' => ( int ) $update,
// or whatever
)
)
);
}
}
add_action( \'wp_insert_post\', \'wpse_185340_post_ping\', 10, 3 );