Exemplo n.º 1
0
 /**
  * Create new WP user and send email notification.
  *
  * @return bool|int
  */
 private function _createWPUser()
 {
     // Generate unique username.
     $i = 1;
     $base = $this->get('name') != '' ? sanitize_user($this->get('name')) : 'client';
     $username = $base;
     while (username_exists($username)) {
         $username = $base . $i;
         ++$i;
     }
     // Generate password.
     $password = wp_generate_password(6, true);
     // Create user.
     $user_id = wp_create_user($username, $password, $this->get('email'));
     if (!$user_id instanceof WP_Error) {
         // Set the role
         $user = new WP_User($user_id);
         $user->set_role('subscriber');
         // Send email notification.
         AB_NotificationSender::sendEmailForNewUser($this, $username, $password);
         return $user_id;
     }
     return false;
 }