コード例 #1
0
 /**
  * Register a user from a GraphUser object.
  *
  * @param GraphUser $userGraph
  *
  * @return integer|boolean
  */
 public function register(GraphUser $userGraph)
 {
     $username = sanitize_user($userGraph->getFirstName(), true);
     $i = '';
     while (username_exists($username . $i)) {
         $i = absint($i);
         $i++;
     }
     $username = $username . $i;
     $userdata = apply_filters($this->container->getSlug() . '.register.user.filter', array('user_pass' => wp_generate_password(), 'user_login' => $username, 'user_nicename' => $username, 'user_email' => $userGraph->getField('email'), 'display_name' => $userGraph->getField('name'), 'nickname' => $username, 'first_name' => $userGraph->getField('first_name'), 'last_name' => $userGraph->getField('last_name'), 'role' => get_option('default_role')));
     $localUserId = wp_insert_user($userdata);
     if ($localUserId instanceof WP_Error) {
         throw new Exception($localUserId->get_error_message(), 500);
     }
     return $localUserId;
 }
コード例 #2
0
 /**
  * Process login with Facebook
  *
  * @param \Facebook\GraphNodes\GraphUser $userNode
  * @return array
  */
 private function _process($userNode)
 {
     $userInfo = [];
     $userInfo['email'] = $userNode->getField('email');
     $userInfo['first_name'] = $userNode->getFirstName();
     $userInfo['last_name'] = $userNode->getLastName();
     $userInfo['facebook_id'] = $userNode->getId();
     return (new ZSocialHelper($userInfo, 'facebook'))->process();
 }