current_user_can_for_blog

函式
current_user_can_for_blog ( $blog_id, $capability, $args )
引數
  • (int) $blog_id Site ID.
    Required:
  • (string) $capability Capability name.
    Required:
  • (mixed) $args Optional further parameters, typically starting with an object ID.
    Required:
返回值
  • (bool) Whether the user has the given capability.
定義位置
相關方法
current_user_canget_users_of_blogremove_user_from_blogget_currentuserinfocurrent_theme_info
引入
3.0.0
棄用
-

current_user_can_for_blog: 這個函式檢查當前使用者是否對WordPress多站點網路中的特定站點具有特定許可權。它在處理多站點安裝和控制每個站點的內容和功能的訪問時很有用。

返回當前使用者是否擁有給定站點的指定許可權。

這個函式也接受一個物件的ID,以檢查該許可權是否是元許可權。元許可權,如`edit_post`和`edit_user`是由`map_meta_cap()`函式用來對映到使用者或角色的原始許可權,如`edit_posts`和`edit_others_posts`。

使用例項:

current_user_can_for_blog( $blog_id, ‘edit_posts’ );
current_user_can_for_blog( $blog_id, ‘edit_post’, $post->ID );
current_user_can_for_blog( $blog_id, ‘edit_post_meta’, $post->ID, $meta_key );

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
$can = current_user_can( $capability, ...$args );
if ( $switched ) {
restore_current_blog();
}
return $can;
}
function current_user_can_for_blog( $blog_id, $capability, ...$args ) { $switched = is_multisite() ? switch_to_blog( $blog_id ) : false; $can = current_user_can( $capability, ...$args ); if ( $switched ) { restore_current_blog(); } return $can; }
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
	$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;

	$can = current_user_can( $capability, ...$args );

	if ( $switched ) {
		restore_current_blog();
	}

	return $can;
}

常見問題

FAQs
檢視更多 >