WordPress向所有ping站点服务发送ping函数:generic_ping
WordPress函数generic_ping()向所有订阅了ping服务的站点发送ping,通知它们有新的内容更新。该函数通常在发布或更新文章时调用,以确保订阅了ping服务的站点能够及时获取到最新信息。
generic_ping( int $post_id ): int
函数参数
$post_id
数据类型:int (必须)
文章ID。
函数返回值
返回$post_id。
函数使用示例
在每次发布新文章时自动发送ping:
function send_ping_after_publish( $post_id, $post, $update ) {
if ( ! $update && $post->post_status == 'publish' ) {
generic_ping( $post_id );
}
}
add_action( 'save_post', 'send_ping_after_publish', 10, 3 );
扩展阅读
generic_ping()函数位于:wp-includes/comment.php
相关函数:
- weblog_ping()
- do_all_pings()