current_user_can_for_blog

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

Description

current_user_can_for_blog( (int) $blog_id, (string) $capability ); 

Parameters (2)

0. $blog_id (int)
The blog id.
1. $capability (string)
Capability or role name.

Usage

  1. if ( !function_exists( 'current_user_can_for_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/capabilities.php'; 
  3.  
  4. // The blog id. 
  5. $blog_id = -1; 
  6.  
  7. // Capability or role name. 
  8. $capability = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = current_user_can_for_blog($blog_id, $capability); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/capabilities.php  
  1. function current_user_can_for_blog( $blog_id, $capability ) { 
  2. $switched = is_multisite() ? switch_to_blog( $blog_id ) : false; 
  3.  
  4. $current_user = wp_get_current_user(); 
  5.  
  6. if ( empty( $current_user ) ) { 
  7. if ( $switched ) { 
  8. return false; 
  9.  
  10. $args = array_slice( func_get_args(), 2 ); 
  11. $args = array_merge( array( $capability ), $args ); 
  12.  
  13. $can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); 
  14.  
  15. if ( $switched ) { 
  16.  
  17. return $can;