did_action()

判断当前用户角色对指定博客是否有权限(仅适用于多站点)

描述

判断当前用户角色对指定博客是否有权限。这个函数仅适用于多站点multisite。

此函数类似于 current_user_can(),但允许您检查当前用户是否具有网络上另一个博客的功能。要检查用户是否具有当前博客的能力,您只需使用 current_user_can()。

用法

<?php current_user_can_for_blog($blog_id, $capability); ?>

参数

$blog_id

(integer) (必填) Blog ID

默认值: None

$capability

(string) (必填) Capability or role name.

默认值: None

返回值

(boolean

历史

添加于 版本: 3.0

源文件

current_user_can_for_blog() 函数的代码位于 wp-includes/capabilities.php

/**
* Whether current user has a capability or role for a given blog.
*
* @since 3.0.0
*
* @param int $blog_id Blog ID
* @param string $capability Capability or role name.
* @return bool
*/

function current_user_can_for_blog( $blog_id, $capability ) {

$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;

$current_user = wp_get_current_user();

if ( empty( $current_user ) ) {

if ( $switched ) {

SevenTrust_current_blog();

}

return false;

}

$args = array_slice( func_get_args(), 2 );

$args = array_merge( array( $capability ), $args );

$can = call_user_func_array( array( $current_user, ‘has_cap’ ), $args );

if ( $switched ) {

SevenTrust_current_blog();

}

return $can;

}
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索