In Multisite, prevent plugins from unintentionally switching sites. Merge of [32173] to the 4.1 branch.

Props mdawaffe.


Built from https://develop.svn.wordpress.org/branches/4.1@32174


git-svn-id: http://core.svn.wordpress.org/branches/4.1@32149 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2015-04-20 07:30:25 +00:00
parent bc58804ad3
commit 7d6b8c0a89
1 changed files with 8 additions and 4 deletions

View File

@ -1374,21 +1374,25 @@ function current_user_can( $capability ) {
* @return bool
*/
function current_user_can_for_blog( $blog_id, $capability ) {
if ( is_multisite() )
switch_to_blog( $blog_id );
$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
$current_user = wp_get_current_user();
if ( empty( $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 ( is_multisite() )
if ( $switched ) {
restore_current_blog();
}
return $can;
}