Make WordPress Core


Ignore:
Timestamp:
04/20/2015 07:26:05 AM (11 years ago)
Author:
pento
Message:

In Multisite, prevent plugins from unintentionally switching sites.

Props mdawaffe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/capabilities.php

    r31673 r32173  
    14041404 */
    14051405function current_user_can_for_blog( $blog_id, $capability ) {
    1406         if ( is_multisite() )
    1407                 switch_to_blog( $blog_id );
     1406        $switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
    14081407
    14091408        $current_user = wp_get_current_user();
    14101409
    1411         if ( empty( $current_user ) )
     1410        if ( empty( $current_user ) ) {
     1411                if ( $switched ) {
     1412                        restore_current_blog();
     1413                }
    14121414                return false;
     1415        }
    14131416
    14141417        $args = array_slice( func_get_args(), 2 );
    … …  
    14171420        $can = call_user_func_array( array( $current_user, 'has_cap' ), $args );
    14181421
    1419         if ( is_multisite() )
     1422        if ( $switched ) {
    14201423                restore_current_blog();
     1424        }
    14211425
    14221426        return $can;
Note: See TracChangeset for help on using the changeset viewer.