Use API to set the user's role. see #11781
git-svn-id: http://svn.automattic.com/wordpress/trunk@12770 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5c5be8cd43
commit
aac0a1230a
|
@ -235,12 +235,12 @@ switch ( $_GET['action'] ) {
|
||||||
$newroles = $_POST[ 'role' ];
|
$newroles = $_POST[ 'role' ];
|
||||||
reset( $newroles );
|
reset( $newroles );
|
||||||
foreach ( (array) $newroles as $userid => $role ) {
|
foreach ( (array) $newroles as $userid => $role ) {
|
||||||
$role_len = strlen( $role );
|
$user = new WP_User($userid);
|
||||||
$existing_role = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$userid' AND meta_key = '" . $blog_prefix. "capabilities'" );
|
if ( ! $user )
|
||||||
if ( false == $existing_role )
|
continue;
|
||||||
$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;}')" );
|
// Hack. Init user caps for given blog.
|
||||||
elseif ( $existing_role != "a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}" )
|
$user->_init_caps($blog_prefix . 'capabilities');
|
||||||
$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->set_role($role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -508,11 +508,16 @@ class WP_User {
|
||||||
* used.
|
* used.
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
|
*
|
||||||
|
* @param string $cap_key Optional capability key
|
||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function _init_caps() {
|
function _init_caps( $cap_key = '' ) {
|
||||||
global $wpdb;
|
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};
|
$this->caps = &$this->{$this->cap_key};
|
||||||
if ( ! is_array( $this->caps ) )
|
if ( ! is_array( $this->caps ) )
|
||||||
$this->caps = array();
|
$this->caps = array();
|
||||||
|
|
Loading…
Reference in New Issue