Ejemplo n.º 1
0
 /**
  * Update the user based on the currently submitted lead.
  *
  * Update the user meta first as the display name is dependent on the first and last name user meta. Afterwards,
  * update the "core" user properties.
  *
  * @param $lead
  * @param $form
  * @param bool $config
  * @return array
  */
 public static function update_user($lead, $form, $config = false)
 {
     if (!$config) {
         $config = self::get_active_config($form, $lead);
     }
     $meta = rgar($config, 'meta');
     $user_id = apply_filters('gform_user_registration_update_user_id', $lead['created_by'], $lead, $form, $config);
     $user_id = apply_filters("gform_user_registration_update_user_id_{$form['id']}", $user_id, $lead, $form, $config);
     // update user meta before display name due to dependency
     self::add_user_meta($user_id, $config, $form, $lead, array());
     // refreshing $user variable because it might have changed during add_user_meta
     $user_obj = new WP_User($user_id);
     $user = get_object_vars($user_obj->data);
     $user_data = self::get_user_data($lead, $form, $config, true);
     $user['user_email'] = $user_data['user_email'];
     $user['display_name'] = self::get_display_name($user['ID'], $config);
     // if password provided, store it for update in $user array and then remove from $lead
     if ($user_data['password']) {
         $user['user_pass'] = $user_data['password'];
         GFUserData::remove_password($form['id'], $lead['id'], rgar($meta, 'password'));
     } else {
         unset($user['user_pass']);
     }
     $user_id = wp_update_user($user);
     $role = rgar($meta, 'role');
     // if a role is provied and it is not the 'preserve' option, update the role
     if (rgar($meta, 'role') && $role != 'gfur_preserve_role') {
         $user_obj->set_role(rgar($meta, 'role'));
     }
     do_action('gform_user_updated', $user_id, $config, $lead, $user_data['password']);
     // return array with user_id, user_login, user_email, and password
     return array_merge(array('user_id' => $user_id), $user_data);
 }
Ejemplo n.º 2
0
 public static function gf_create_user($entry, $form, $fulfilled = false)
 {
     // if the entry is marked as spam
     if (rgar($entry, 'status') == 'spam') {
         return;
     }
     $config = self::get_config($form['id']);
     $meta = rgar($config, 'meta');
     // if there is no registration feed or the registration condition is not met or the feed is not active, abandon ship
     if (!$config || !self::registration_condition_met($form, $config, $entry) || !$config['is_active']) {
         return;
     }
     // if PayPal Add-on was used for this entry, integrate
     $paypal_config = self::get_paypal_config($form["id"], $entry);
     if ($paypal_config) {
         //$paypal_config = self::get_paypal_config($form["id"], $entry);
         $order_total = GFCommon::get_order_total($form, $entry);
         // delay the registration IF:
         // - the delay registration option is checked
         // - the order total does NOT equal zero (no delay since there will never be a payment)
         // - the payment has not already been fulfilled
         if ($paypal_config && $paypal_config['meta']['delay_registration'] && $order_total != 0 && $fulfilled != true) {
             return;
         }
     }
     $user_name = apply_filters("gform_username_{$form['id']}", apply_filters('gform_username', self::get_meta_value('username', $config, $form, $entry), $config, $form, $entry), $config, $form, $entry);
     $user_email = self::get_meta_value('email', $config, $form, $entry);
     $user_pass = self::get_meta_value('password', $config, $form, $entry);
     if (empty($user_name) || empty($user_email)) {
         return;
     }
     if (!function_exists('username_exists')) {
         require_once ABSPATH . WPINC . "/registration.php";
     }
     $user_id = username_exists($user_name);
     // create the user and password, then add user meta
     if (!$user_id && empty($user_pass)) {
         $user_pass = wp_generate_password();
         $user_id = wp_create_user($user_name, $user_pass, $user_email);
         if (is_wp_error($user_id)) {
             return;
         }
         update_user_option($user_id, 'default_password_nag', true, false);
         self::add_user_meta($user_id, $config, $form, $entry, array());
     } else {
         if (!$user_id) {
             $user_id = wp_create_user($user_name, $user_pass, $user_email);
             if (is_wp_error($user_id)) {
                 return;
             }
             GFUserData::remove_password($form['id'], $entry['id'], rgar($meta, 'password'));
             self::add_user_meta($user_id, $config, $form, $entry, array());
         } else {
             // if user with this username already exists, abort user registration
             return;
         }
     }
     if (rgar($meta, 'role')) {
         $user = new WP_User($user_id);
         $user->set_role(rgar($meta, 'role'));
     }
     // set post author
     if (!empty($entry['post_id']) && rgar($meta, 'set_post_author')) {
         self::attribute_post_author($user_id, $entry['post_id']);
     }
     // send user/admin notifications
     if (rgar($meta, 'notification')) {
         wp_new_user_notification($user_id, $user_pass);
     } else {
         wp_new_user_notification($user_id, "");
         // sending a blank password only sends notification to admin
     }
     do_action('gform_user_registered', $user_id, $config, $entry, $user_pass);
 }