diff --git a/wp-admin/ms-edit.php b/wp-admin/ms-edit.php index 7a23d1f18..19a1e5d61 100644 --- a/wp-admin/ms-edit.php +++ b/wp-admin/ms-edit.php @@ -235,12 +235,12 @@ switch ( $_GET['action'] ) { $newroles = $_POST[ 'role' ]; reset( $newroles ); foreach ( (array) $newroles as $userid => $role ) { - $role_len = strlen( $role ); - $existing_role = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$userid' AND meta_key = '" . $blog_prefix. "capabilities'" ); - if ( false == $existing_role ) - $wpdb->query( "INSERT INTO " . $wpdb->usermeta . "( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '$userid', '" . $blog_prefix . "capabilities', 'a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}')" ); - elseif ( $existing_role != "a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}" ) - $wpdb->query( "UPDATE $wpdb->usermeta SET meta_value = 'a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}' WHERE user_id = '$userid' AND meta_key = '" . $blog_prefix . "capabilities'" ); + $user = new WP_User($userid); + if ( ! $user ) + continue; + // Hack. Init user caps for given blog. + $user->_init_caps($blog_prefix . 'capabilities'); + $user->set_role($role); } } diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 47f7d71b2..ffc49da01 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -508,11 +508,16 @@ class WP_User { * used. * * @since 2.1.0 + * + * @param string $cap_key Optional capability key * @access protected */ - function _init_caps() { + function _init_caps( $cap_key = '' ) { global $wpdb; - $this->cap_key = $wpdb->prefix . 'capabilities'; + if ( empty($cap_key) ) + $this->cap_key = $wpdb->prefix . 'capabilities'; + else + $this->cap_key = $cap_key; $this->caps = &$this->{$this->cap_key}; if ( ! is_array( $this->caps ) ) $this->caps = array();