Esempio n. 1
0
 /**
  * Adds WordPress user to WPL
  * @author Howard <*****@*****.**>
  * @static
  * @param int $user_id
  * @param int $group_id
  * @return boolean
  */
 public static function add_user_to_wpl($user_id, $group_id = -1)
 {
     /** first validation **/
     if (wpl_users::get_wpl_user($user_id)) {
         return true;
     }
     $user_data = wpl_users::get_user($user_id);
     $default_data = wpl_users::get_wpl_data($group_id);
     $forbidden_fields = array('id', 'first_name', 'last_name', 'main_email', 'blog_id');
     $auto_query1 = '';
     $auto_query2 = '';
     foreach ($default_data as $key => $value) {
         if (in_array($key, $forbidden_fields)) {
             continue;
         }
         $auto_query1 .= "`{$key}`,";
         $auto_query2 .= "'{$value}',";
     }
     if ($user_data) {
         $auto_query1 .= "`first_name`,`last_name`,`main_email`,";
         $auto_query2 .= "'" . $user_data->data->meta['first_name'] . "','" . $user_data->data->meta['last_name'] . "','" . $user_data->data->user_email . "',";
     }
     $auto_query1 = trim($auto_query1, ', ');
     $auto_query2 = trim($auto_query2, ', ');
     $query = "INSERT INTO `#__wpl_users` (`id`, " . $auto_query1 . ") VALUES ('" . $user_id . "', " . $auto_query2 . ")";
     $result = wpl_db::q($query);
     /** trigger event **/
     wpl_global::event_handler('user_added_to_wpl', array('id' => $user_id));
     /** finalize user **/
     wpl_users::finalize($user_id);
     return $result;
 }
Esempio n. 2
0
 private function finalize($user_id)
 {
     wpl_users::finalize($user_id);
     $res = 1;
     $message = $res ? __('Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN);
     $data = NULL;
     $response = array('success' => $res, 'message' => $message, 'data' => $data);
     echo json_encode($response);
     exit;
 }