Exemplo n.º 1
0
 public static function gf_create_user($entry, $form, $fulfilled = false)
 {
     self::log_debug("form #{$form['id']} - starting gf_create_user().");
     global $wpdb;
     // if the entry is marked as spam
     if (rgar($entry, 'status') == 'spam') {
         self::log_debug('gf_create_user(): aborting. Entry is marked as spam.');
         return;
     }
     $config = self::get_active_config($form, $entry);
     $is_update_feed = rgars($config, 'meta/feed_type') == 'update';
     // if there is no registration feed or the feed is not active, abandon ship
     if (!$config || !$config['is_active']) {
         self::log_debug('gf_create_user(): aborting. No feed or feed is inactive.');
         return;
     }
     $user_data = self::get_user_data($entry, $form, $config, $is_update_feed);
     if (!$user_data) {
         self::log_debug('gf_create_user(): aborting. user_login or user_email are empty.');
         return;
     }
     // if PayPal Add-on was used for this entry, integrate
     $paypal_config = self::get_paypal_config($form["id"], $entry);
     $delay_paypal_registration = 0;
     $password = '';
     if ($paypal_config) {
         $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
         $delay_paypal_registration = $paypal_config['meta']['delay_registration'];
         if ($paypal_config && $delay_paypal_registration && $order_total != 0 && !$fulfilled) {
             self::log_debug('gf_create_user(): aborting. Registration delayed by PayPal feed configuration.');
             //Saving encrypted password in meta
             gform_update_meta($entry['id'], 'userregistration_password', self::encrypt($user_data['password']));
             return;
         } else {
             if ($paypal_config && $delay_paypal_registration && $order_total != 0 && $fulfilled) {
                 //reading encrypted password from meta and removing meta
                 $password = gform_get_meta($entry['id'], 'userregistration_password');
                 if ($password) {
                     $password = self::decrypt($password);
                     gform_delete_meta($entry['id'], 'userregistration_password');
                 }
             }
         }
     }
     // provide filter to allow add-ons to disable registration if needed
     $disable_registration = apply_filters('gform_disable_registration', false, $form, $entry, $fulfilled);
     if ($disable_registration) {
         self::log_debug('gf_create_user(): aborting. gform_disable_registration hook was used.');
         return;
     }
     $user_activation = rgars($config, 'meta/user_activation');
     // if about to create user, check if activation required... only use activation if payment is not fulfilled by payment
     //if manual activation and paypal set to delay registration and paypal fulfilled, need to put in signups table
     if (!$is_update_feed && $user_activation && !$fulfilled || !$is_update_feed && $user_activation && $fulfilled && $delay_paypal_registration) {
         require_once self::get_base_path() . '/includes/signups.php';
         GFUserSignups::prep_signups_functionality();
         $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email'], 'password' => self::encrypt($user_data['password']));
         $meta = apply_filters('gform_user_registration_signup_meta', $meta, $form, $entry, $config);
         $meta = apply_filters("gform_user_registration_signup_meta_{$form['id']}", $meta, $form, $entry, $config);
         $ms_options = rgars($config, 'meta/multisite_options');
         // save current user details in wp_signups for future activation
         if (is_multisite() && rgar($ms_options, 'create_site') && ($site_data = self::get_site_data($entry, $form, $config))) {
             wpmu_signup_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_data['user_login'], $user_data['user_email'], $meta);
         } else {
             // wpmu_signup_user() does the following sanitization of the user_login before saving it to the database,
             // we can run this same code here to allow successful retrievel of the activation_key without actually
             // changing the user name when it is activated. 'd smith' => 'dsmith', but when activated, username is 'd smith'.
             $user_data['user_login'] = preg_replace('/\\s+/', '', sanitize_user($user_data['user_login'], true));
             self::log_debug("Calling wpmu_signup_user (sends email with activation link) with login: "******" email: " . $user_data['user_email'] . " meta: " . print_r($meta, true));
             wpmu_signup_user($user_data['user_login'], $user_data['user_email'], $meta);
             self::log_debug("Done with wpmu_signup_user");
         }
         $activation_key = $wpdb->get_var($wpdb->prepare("SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s ORDER BY registered DESC LIMIT 1", $user_data['user_login']));
         // used for filtering on activation listing UI
         GFUserSignups::add_signup_meta($entry['id'], $activation_key);
         // abort current sign up, user must activate
         return;
     }
     if ($is_update_feed) {
         self::update_user($entry, $form, $config);
     } else {
         //only run create_user when manual/email activation NOT set
         if (!$user_activation) {
             self::log_debug("in gf_create_user - calling create_user");
             self::create_user($entry, $form, $config, $password);
         }
     }
 }