Make WordPress Core


Ignore:
Timestamp:
09/27/2017 09:09:11 PM (7 years ago)
Author:
flixos90
Message:

Multisite: Initialize a user's roles correctly when setting them up for a different site.

While it has always been possible to initialize a user's roles and capabilities for another site than the current one in a multisite, the actual roles available were not switched prior to this change, possibly causing invalid roles to show up or actually valid capabilities not being available.

In order to fix this bug in a clean way, relevant parts of the WP_User class have been refactored. The ID of the site for which capabilities are currently initialized are now stored in a private property WP_User::$site_id. The WP_User::for_blog( $blog_id ) and WP_User::_init_caps( $cap_key ) methods have been deprecated in favor of WP_User::for_site( $site_id ). In addition, a new method WP_User::get_site_id() has been introduced to retrieve the site ID for which the user's capabilities are currently initialized.

Props ryanduff, jeremyfelt, flixos90.
Fixes #36961.

File:
1 edited

Legend:

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

    r41373 r41624  
    851851        $wp_roles = new WP_Roles();
    852852        $current_user = wp_get_current_user();
    853         $current_user->for_blog( $new_blog );
     853        $current_user->for_site( $new_blog );
    854854    }
    855855
     
    925925        $wp_roles = new WP_Roles();
    926926        $current_user = wp_get_current_user();
    927         $current_user->for_blog( $blog );
     927        $current_user->for_site( $blog );
    928928    }
    929929
Note: See TracChangeset for help on using the changeset viewer.