コード例 #1
0
ファイル: logic.php プロジェクト: Br3nda/openmicroblogger
 /**
  * Create a new WordPress user with the specified identity URL and user data.
  *
  * @param string $identity_url OpenID to associate with the newly
  * created account
  * @param array $user_data array of user data
  */
 function create_new_user($identity_url, &$user_data)
 {
     global $wpdb, $openid;
     // Identity URL is new, so create a user
     @(include_once ABSPATH . 'wp-admin/upgrade-functions.php');
     // 2.1
     @(include_once ABSPATH . WPINC . '/registration-functions.php');
     // 2.0.4
     $user_data['user_login'] = $wpdb->escape(WordPressOpenID_Logic::generate_new_username($identity_url));
     $user_data['user_pass'] = substr(md5(uniqid(microtime())), 0, 7);
     $user_id = wp_insert_user($user_data);
     $openid->log->debug("wp_create_user( {$user_data} )  returned {$user_id} ");
     if ($user_id) {
         // created ok
         $user_data['ID'] = $user_id;
         // XXX this all looks redundant, see WordPressOpenID_Logic::set_current_user
         $openid->log->debug("OpenIDConsumer: Created new user {$user_id} : {$username} and metadata: " . var_export($user_data, true));
         $user = new WP_User($user_id);
         if (!wp_login($user->user_login, $user_data['user_pass'])) {
             $openid->error = 'User was created fine, but wp_login() for the new user failed. ' . 'This is probably a bug.';
             $openid->action = 'error';
             $openid->log->err($openid->error);
             return;
         }
         // notify of user creation
         wp_new_user_notification($user->user_login);
         wp_clearcookie();
         wp_setcookie($user->user_login, md5($user->user_pass), true, '', '', true);
         // Bind the provided identity to the just-created user
         global $userdata;
         $userdata = get_userdata($user_id);
         $store = WordPressOpenID_Logic::getStore();
         $store->insert_identity($user_id, $identity_url);
         $openid->action = 'redirect';
         if (!$user->has_cap('edit_posts')) {
             $redirect_to = '/wp-admin/profile.php';
         }
     } else {
         // failed to create user for some reason.
         $openid->error = 'OpenID authentication successful, but failed to create WordPress user. ' . 'This is probably a bug.';
         $openid->action = 'error';
         $openid->log->error($openid->error);
     }
 }