function process_facebook_registration()
 {
     // Should we even be here?
     if ($this->data->get_option('wdfb_connect', 'force_facebook_registration')) {
         global $pagenow;
         if ('wp-signup.php' == $pagenow) {
             $_GET['fb_registration_page'] = 1;
         }
         if ('wp-login.php' == $pagenow && isset($_GET['action']) && 'register' == $_GET['action']) {
             $_GET['fb_registration_page'] = 1;
         }
         if (defined('BP_VERSION')) {
             // BuddyPress :/
             global $bp;
             if ('register' == $bp->current_component) {
                 $_GET['fb_registration_page'] = 1;
             }
         }
     }
     if (!isset($_GET['fb_registration_page']) && !isset($_GET['fb_register'])) {
         return false;
     }
     // Are registrations allowed?
     $wp_grant_blog = false;
     if (is_multisite()) {
         $reg = get_site_option('registration');
         if ('all' == $reg) {
             $wp_grant_blog = true;
         } else {
             if ('user' != $reg) {
                 return false;
             }
         }
     } else {
         if (!(int) get_option('users_can_register')) {
             return false;
         }
     }
     $wp_grant_blog = apply_filters('wdfb-registration-allow_blog_creation', $wp_grant_blog);
     // We're here, so registration is allowed
     $registration_success = false;
     $user_id = false;
     $errors = array();
     // Process registration data
     if (isset($_GET['fb_register'])) {
         list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
         $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
         // We're good here
         if ($data['registration']) {
             $user_id = $this->model->register_fb_user();
             if ($user_id && $wp_grant_blog) {
                 $new_blog_title = '';
                 $new_blog_url = '';
                 remove_filter('wpmu_validate_blog_signup', 'signup_nonce_check');
                 // Set up proper blog name
                 $blog_domain = apply_filters('wdfb-registration-blog_domain-sanitize_domain', preg_replace('/[^a-z0-9]/', '', strtolower($data['registration']['blog_domain'])), $data['registration']['blog_domain']);
                 // All numbers? Fix that
                 if (preg_match('/^[0-9]$/', $blog_domain)) {
                     $letters = shuffle(range('a', 'z'));
                     $blog_domain .= $letters[0];
                 }
                 $blog_domain = apply_filters('wdfb-registration-blog_domain', $blog_domain, $data['registration']['blog_domain']);
                 // Set up proper title
                 $blog_title = $data['registration']['blog_title'];
                 $blog_title = $blog_title ? $blog_title : apply_filters('wdfb-registration-default_blog_title', __("My new blog", 'wdfb'));
                 $blog_title = apply_filters('wdfb-registration-blog_title', $blog_title, $data['registration']['blog_title']);
                 $result = wpmu_validate_blog_signup($blog_domain, $blog_title);
                 $iteration = 0;
                 // Blog domain failed, try making it unique
                 while ($result['errors']->get_error_code()) {
                     if ($iteration > 10) {
                         break;
                     }
                     // We should really gtfo
                     $blog_domain .= rand();
                     $result = wpmu_validate_blog_signup($blog_domain, $blog_title);
                     $iteration++;
                 }
                 if (!$result['errors']->get_error_code()) {
                     global $current_site;
                     $blog_meta = array('public' => 1);
                     $blog_id = wpmu_create_blog($result['domain'], $result['path'], $result['blog_title'], $user_id, $blog_meta, $current_site->id);
                     $new_blog_title = $result['blog_title'];
                     $new_blog_url = get_blog_option($blog_id, 'siteurl');
                     $registration_success = true;
                 } else {
                     // Remove user
                     $this->model->delete_wp_user($user_id);
                     $errors = array_merge($errors, array_values($result['errors']->errors));
                 }
             } else {
                 if ($user_id) {
                     $registration_success = true;
                 } else {
                     $msg = Wdfb_ErrorRegistry::get_last_error_message();
                     if ($msg) {
                         $errors[] = $msg;
                     }
                     $errors[] = __('Could not register such user', 'wdfb');
                 }
             }
         }
     }
     // Successful registration stuff
     if ($registration_success) {
         // Trigger actions
         if ($user_id) {
             do_action('wdfb-registration-facebook_registration', $user_id);
             do_action('wdfb-registration-facebook_regular_registration', $user_id);
         }
         // Record activities, if told so
         if ($user_id && defined('BP_VERSION') && $this->data->get_option('wdfb_connect', 'update_feed_on_registration')) {
             if (function_exists('bp_core_new_user_activity')) {
                 bp_core_new_user_activity($user_id);
             }
         }
         // Attempt to auto-login the user
         if ($this->data->get_option('wdfb_connect', 'autologin_after_registration') && isset($_GET['fb_register'])) {
             $fb_user = $this->model->fb->getUser();
             if ($fb_user && $user_id) {
                 // Don't try too hard
                 $user = get_userdata($user_id);
                 wp_set_current_user($user->ID, $user->user_login);
                 wp_set_auth_cookie($user->ID);
                 // Logged in with Facebook, yay
                 do_action('wp_login', $user->user_login);
             }
         }
     }
     // Allow registration page templating
     // By KFUK-KFUM
     // Thank you so much!
     $page = isset($_GET['fb_register']) && $registration_success ? $this->get_template_page('registration_page_success.php') : $this->get_template_page('registration_page.php');
     require_once $page;
     exit;
 }
 function error($function, $exception)
 {
     Wdfb_ErrorRegistry::store($exception);
     $info = is_object($exception) && method_exists($exception, 'getMessage') ? $exception->getMessage() : $exception;
     $this->_update_error_queue(array('date' => time(), 'area' => $function, 'user_id' => get_current_user_id(), 'type' => 'exception', 'info' => $info));
 }
 public static function clear()
 {
     self::$_errors = array();
 }