WordPress.org

Make WordPress Core

Changeset 12770


Ignore:
Timestamp:
01/19/2010 08:12:04 PM (12 years ago)
Author:
ryan
Message:

Use API to set the user's role. see #11781

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/ms-edit.php

    r12752 r12770  
    236236            reset( $newroles );
    237237            foreach ( (array) $newroles as $userid => $role ) {
    238                 $role_len = strlen( $role );
    239                 $existing_role = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$userid'  AND meta_key = '" . $blog_prefix. "capabilities'" );
    240                 if ( false == $existing_role )
    241                     $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;}')" );
    242                 elseif ( $existing_role != "a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}" )
    243                     $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'" );
     238                $user = new WP_User($userid);
     239                if ( ! $user )
     240                    continue;
     241                // Hack. Init user caps for given blog.
     242                $user->_init_caps($blog_prefix . 'capabilities');
     243                $user->set_role($role);
    244244            }
    245245        }
  • trunk/wp-includes/capabilities.php

    r12753 r12770  
    509509     *
    510510     * @since 2.1.0
     511     *
     512     * @param string $cap_key Optional capability key
    511513     * @access protected
    512514     */
    513     function _init_caps() {
     515    function _init_caps( $cap_key = '' ) {
    514516        global $wpdb;
    515         $this->cap_key = $wpdb->prefix . 'capabilities';
     517        if ( empty($cap_key) )
     518            $this->cap_key = $wpdb->prefix . 'capabilities';
     519        else
     520            $this->cap_key = $cap_key;
    516521        $this->caps = &$this->{$this->cap_key};
    517522        if ( ! is_array( $this->caps ) )
Note: See TracChangeset for help on using the changeset viewer.