函数文档

current_user_can_for_blog()

💡 云策文档标注

概述

current_user_can_for_blog() 函数用于检查当前用户是否在指定站点上拥有特定权限。该函数自 WordPress 6.7.0 起已弃用,建议使用 current_user_can_for_site() 替代。

关键要点

  • 函数功能:返回当前用户在给定站点上是否具有指定能力(capability)。
  • 参数说明:$blog_id(站点ID,必需)、$capability(能力名称,必需)、$args(可选参数,通常以对象ID开头)。
  • 返回值:布尔值,表示用户是否拥有该能力。
  • 弃用状态:自 WordPress 6.7.0 起弃用,推荐使用 current_user_can_for_site()。
  • 历史版本:5.8.0 版本通过切换到博客后包装 current_user_can() 实现,5.3.0 版本正式化 ...$args 参数,3.0.0 版本引入。

注意事项

在开发中,应优先使用 current_user_can_for_site() 以避免弃用警告,并确保代码兼容性。


📄 原文内容

Returns whether the current user has the specified capability for a given site.

Parameters

$blog_idintrequired
Site ID.
$capabilitystringrequired
Capability name.
$argsmixedoptional
Optional further parameters, typically starting with an object ID.

Return

bool Whether the user has the given capability.

Source

function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
	return current_user_can_for_site( $blog_id, $capability, ...$args );
}

Changelog

Version Description
6.7.0 Deprecated. Use current_user_can_for_site() instead.
5.8.0 Wraps current_user_can() after switching to blog.
5.3.0 Formalized the existing and already documented ...$args parameter by adding it to the function signature.
3.0.0 Introduced.