函数文档

generic_ping()

💡 云策文档标注

概述

generic_ping() 函数用于向所有 ping 站点服务发送 ping 通知,通常用于新文章发布时触发更新通知。

关键要点

  • 函数接受一个必需的 $post_id 参数,表示文章 ID,并返回相同的 ID。
  • 通过 get_option('ping_sites') 获取配置的 ping 服务列表,按换行符分割并遍历每个服务。
  • 使用 weblog_ping() 函数向每个非空服务发送 ping。

代码示例

function generic_ping( $post_id = 0 ) {
	$services = get_option( 'ping_sites' );

	$services = explode( "n", $services );
	foreach ( (array) $services as $service ) {
		$service = trim( $service );
		if ( '' !== $service ) {
			weblog_ping( $service );
		}
	}

	return $post_id;
}

注意事项

  • 此函数自 WordPress 1.2.0 版本引入,是核心功能的一部分。
  • 依赖 weblog_ping() 和 get_option() 函数,确保这些函数可用。
  • ping 服务列表存储在 'ping_sites' 选项中,需在 WordPress 设置中配置。

📄 原文内容

Sends pings to all of the ping site services.

Parameters

$post_idintrequired
Post ID.

Return

int Same post ID as provided.

Source

function generic_ping( $post_id = 0 ) {
	$services = get_option( 'ping_sites' );

	$services = explode( "n", $services );
	foreach ( (array) $services as $service ) {
		$service = trim( $service );
		if ( '' !== $service ) {
			weblog_ping( $service );
		}
	}

	return $post_id;
}

Changelog

Version Description
1.2.0 Introduced.