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

Props mdawaffe, pento.


Built from https://develop.svn.wordpress.org/branches/3.9@32200


git-svn-id: http://core.svn.wordpress.org/branches/3.9@32173 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2015-04-20 13:23:15 +00:00
parent 6c6ea88f7d
commit 7bd9e93fef
1 changed files with 8 additions and 4 deletions

View File

@ -1347,21 +1347,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;
}