Exemplo n.º 1
0
 public static function activate_blog($data, $trial = false, $period = 1, $level = 1, $expire = false)
 {
     global $psts, $wpdb;
     $user_pass = false;
     if (!is_array($data)) {
         $key = $data;
     } else {
         $key = isset($data['activation_key']) ? $data['activation_key'] : false;
         $user_pass = isset($data['new_blog_details']['user_pass']) ? $data['new_blog_details']['user_pass'] : false;
     }
     if (empty($key)) {
         return false;
     }
     // In case we're in session
     $session_data['new_blog_details'] = ProSites_Helper_Session::session('new_blog_details');
     $user_pass = empty($user_pass) && isset($session_data['new_blog_details']['user_pass']) ? $session_data['new_blog_details']['user_pass'] : $user_pass;
     if (!empty($user_pass)) {
         self::$temp_pass = $user_pass;
         add_filter('update_welcome_email', array('ProSites_Helper_Registration', 'update_welcome_email'), 10, 6);
     }
     // Activate the user signup
     $result = wpmu_activate_signup($key);
     $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $key));
     // If the blog has already been activated, we still need some information from the signup table
     if (is_wp_error($result)) {
         $result = array();
         if (empty($signup)) {
             return 0;
         }
         $user_id = username_exists($signup->user_login);
         $blog_id = domain_exists($signup->domain, $signup->path, $wpdb->siteid);
         // As a fallback, try the site domain
         if (empty($blog_id)) {
             $domain = $wpdb->get_var($wpdb->prepare("SELECT domain FROM {$wpdb->site} WHERE id = %d", $wpdb->siteid));
             $blog_id = domain_exists($domain, $signup->path, $wpdb->siteid);
         }
         $result['user_id'] = $user_id;
         $result['blog_id'] = (int) $blog_id;
     }
     /**
      * Update coupon information
      */
     if (!empty($signup)) {
         //				$blog_id = $result['blog_id'];
         //				$signup_meta = maybe_unserialize( $signup->meta );
         //
         //				// Unlikely that this will have a coupon, but make sure
         //				$used = (array) get_blog_option( $blog_id, 'psts_used_coupons' );
         //
         //				// Is there a coupon stored in the signup_meta?
         //				if( isset( $signup_meta['psts_used_coupons'] ) && ! empty( $signup_meta['psts_used_coupons'] ) && is_array( $signup_meta['psts_used_coupons'] ) ) {
         //					// Merge and make sure we don't record the same coupon twice
         //					$used = array_merge( $used, $signup_meta['psts_used_coupons'] );
         //					$used = array_unique( $used );
         //					// Remove from signup meta
         //					unset( $signup_meta['psts_used_coupons'] );
         //					$psts->update_signup_meta( $signup_meta, $key );
         //				}
         //				if( ! empty( $used ) ) {
         //					// Add to blog options
         //					update_blog_option( $blog_id, 'psts_used_coupons', $used );
         //				}
     }
     /**
      * @todo: Make sure we dont over extend
      */
     //Set Trial
     if ($trial) {
         $trial_days = $psts->get_setting('trial_days', 0);
         // Set to first level for $trial_days
         $psts->extend($result['blog_id'], $period, 'Trial', $level, '', strtotime('+ ' . $trial_days . ' days'));
         //Redirect to checkout on next signup
         /**
          * @todo May not be needed here anymore
          */
         //update_blog_option( $result['blog_id'], 'psts_signed_up', 1 );
     }
     if (!empty($user_pass)) {
         $result['password'] = $user_pass;
     }
     // Contains $result['password'] for new users
     return $result;
 }