current_user_can_for_blog() - WordPress 函数参考中文文档

返回介绍

current_user_can_for_blog()

发布于 2017-09-10 字数1687 浏览 959 评论 0

current_user_can_for_blog( int $blog_id,  string $capability )

Whether current user has a capability or role for a given site.


描述


参数

$blog_id

(int)
(Required)
Site ID.

$capability

(string)
(Required)
Capability or role name.


返回值

(bool)


源代码

File: wp-includes/capabilities.php

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 ) {
			restore_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 ) {
		restore_current_blog();
	}

	return $can;
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/pluggable.php:
    wp_get_current_user()
  • wp-includes/load.php:
    is_multisite()
  • wp-includes/ms-blogs.php:
    switch_to_blog()
  • wp-includes/ms-blogs.php:
    restore_current_blog()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!