函数文档

wpmu_update_blogs_date()

💡 云策文档标注

概述

wpmu_update_blogs_date() 函数用于更新当前站点的 last_updated 字段,通常用于多站点网络(Multisite)中记录站点最后更新时间。

关键要点

  • 函数通过 get_current_blog_id() 获取当前站点 ID,并使用 update_blog_details() 更新 last_updated 字段为当前时间(UTC 格式)。
  • 更新后触发 wpmu_blog_updated 动作钩子,允许开发者添加自定义回调。
  • 该函数自 WordPress MU 3.0.0 版本引入,常用于发布或删除文章时自动更新站点日期。

代码示例

function wpmu_update_blogs_date() {
    $site_id = get_current_blog_id();
    update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) );
    do_action( 'wpmu_blog_updated', $site_id );
}

注意事项

  • 函数主要用于多站点环境,单站点中可能不适用。
  • 更新使用 UTC 时间,确保跨时区一致性。
  • 可通过 wpmu_blog_updated 钩子扩展功能,例如记录日志或发送通知。

📄 原文内容

Updates the last_updated field for the current site.

Source

function wpmu_update_blogs_date() {
	$site_id = get_current_blog_id();

	update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) );
	/**
	 * Fires after the blog details are updated.
	 *
	 * @since MU (3.0.0)
	 *
	 * @param int $blog_id Site ID.
	 */
	do_action( 'wpmu_blog_updated', $site_id );
}

Hooks

do_action( ‘wpmu_blog_updated’, int $blog_id )

Fires after the blog details are updated.

Changelog

Version Description
MU (3.0.0) Introduced.