function validate($errors) { $user = apply_filters('ns_wp_create_site_admin', wp_get_current_user()); $site_meta = apply_filters('ns_wp_create_site_meta', array("public" => 1)); // use wp's built in wpmu_validate_blog_signup validation for all new site vars // also, use a test on a known valid name/title to filter out any validation errors added by other plugins via the wpmu_validate_blog_signup filter $baseline_validation = wpmu_validate_blog_signup('1000000', 'NS Cloner Test'); $current_site_validation = wpmu_validate_blog_signup($this->cloner->request["target_name"], $this->cloner->request["target_title"], $user); $site_errors = array_diff($current_site_validation['errors']->get_error_messages(), $baseline_validation['errors']->get_error_messages()); foreach ($site_errors as $error) { // if the error is only because there are dashes in the site name, ignore the error since that's fine/allowable if ($error == 'Only lowercase letters (a-z) and numbers are allowed.' && preg_match('/^[a-z0-9-]+$/', $this->cloner->request["target_name"])) { continue; } // otherwise add the error to the list so it can get sent back $errors[] = array('message' => $error, 'section' => $this->id); } return $errors; }
/** * Create site */ function ns_wp_create_site($site_name, $site_title, $logfile) { $user = apply_filters('ns_wp_create_site_admin', wp_get_current_user()); $site_meta = apply_filters('ns_wp_create_site_meta', array("public" => 1)); // use wp's built in wpmu_validate_blog_signup validation for all new site vars // also, use a test on a known valid name/title to filter out any validation errors added by other plugins via the wpmu_validate_blog_signup filter $baseline_validation = wpmu_validate_blog_signup('1000000', 'NS Cloner Test'); $site_data = wpmu_validate_blog_signup($site_name, $site_title, $user); $site_errors = array_diff($baseline_validation['errors']->get_error_messages(), $site_data['errors']->get_error_messages()); if (!empty($site_errors) && false) { ns_log_write(array("Error creating site with name '{$site_name}' and title '{$site_title}'. One or more problems errors detected by WP:", $site_errors), $logfile); return false; } $site_id = wpmu_create_blog($site_data["domain"], $site_data["path"], $site_title, $site_data["user"]->ID, $site_meta, get_current_site()->id); if (!is_wp_error($site_id)) { ns_log_write("New site with name '{$site_name}' and title '{$site_title}' (" . get_site_url($site_id) . ") successfully created!", $logfile); return $site_id; } else { ns_log_write("Error creating site with domain '{$site_name}' and path '{$site_title}' - " . $site_id->get_error_message(), $logfile); return false; } }
/** * bp_groupblog_validate_blog_form() * * This function validates that the blog does not exist already, illegal names, etc... */ function bp_groupblog_validate_blog_form() { $user = ''; if (is_user_logged_in()) { $user = wp_get_current_user(); } $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user); $errors = $result['errors']; // we only want to filter if there is an error if (!is_object($errors)) { return $result; } $checks = get_site_option('bp_groupblog_blog_defaults_options'); // create a new var to hold errors $newerrors = new WP_Error(); // loop through the errors and look for the one we are concerned with foreach ($errors->errors as $key => $value) { // if the error is with the blog name, check to see which one if ($key == 'blogname') { foreach ($value as $subkey => $subvalue) { switch ($subvalue) { case 'Only lowercase letters and numbers allowed': $allowedchars = ''; if ($checks['allowdashes'] == 1) { $allowedchars .= '-'; } if ($checks['allowunderscores'] == 1) { $allowedchars .= '_'; } $allowed = '/[a-z0-9' . $allowedchars . ']+/'; preg_match($allowed, $result['blogname'], $maybe); if ($result['blogname'] != $maybe[0]) { //still fails, so add an error to the object $newerrors->add('blogname', __("Only lowercase letters and numbers allowed", 'groupblog')); } continue; case 'Blog name must be at least 4 characters': if (strlen($result['blogname']) < $checks[minlength] && !is_super_admin()) { $newerrors->add('blogname', __("Blog name must be at least " . $checks[minlength] . " characters", 'groupblog')); } continue; case "Sorry, blog names may not contain the character '_'!": if ($checks['allowunderscores'] != 1) { $newerrors->add('blogname', __("Sorry, blog names may not contain the character '_'!", 'groupblog')); } continue; case 'Sorry, blog names must have letters too!': if ($checks['allownumeric'] != 1) { $newerrors->add('blogname', __("Sorry, blog names must have letters too!", 'groupblog')); } continue; default: $newerrors->add('blogname', $subvalue); } // end switch } } else { //Add all other errors into the error object, but they're in sub-arrays, so loop through to get the right stuff. foreach ($value as $subkey => $subvalue) { $newerrors->add($key, $subvalue); } } } //unset the error object from the results & rest it with our new errors unset($result['errors']); $result['errors'] = $newerrors; return $result; }
/** * Displays the registration page * * @since 6.1 * @access public * * @param object $template Theme_My_Login_Template object */ public function tml_display_register(&$template) { global $wpdb, $blogname, $blog_title, $domain, $path, $active_signup; $theme_my_login = Theme_My_Login::get_object(); do_action('before_signup_form'); echo '<div class="login mu_register" id="theme-my-login' . esc_attr($template->get_option('instance')) . '">'; $active_signup = get_site_option('registration'); if (!$active_signup) { $active_signup = 'all'; } $active_signup = apply_filters('wpmu_active_signup', $active_signup); // return "all", "none", "blog" or "user" // Make the signup type translatable. $i18n_signup['all'] = _x('all', 'Multisite active signup type'); $i18n_signup['none'] = _x('none', 'Multisite active signup type'); $i18n_signup['blog'] = _x('blog', 'Multisite active signup type'); $i18n_signup['user'] = _x('user', 'Multisite active signup type'); if (is_super_admin()) { echo '<p class="message">' . sprintf(__('Greetings Site Administrator! You are currently allowing “%s” registrations. To change or disable registration go to your <a href="%s">Options page</a>.', 'theme-my-login'), $i18n_signup[$active_signup], esc_url(network_admin_url('ms-options.php'))) . '</p>'; } $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null; $current_user = wp_get_current_user(); if ($active_signup == "none") { _e('Registration has been disabled.', 'theme-my-login'); } elseif ($active_signup == 'blog' && !is_user_logged_in()) { printf(__('You must first <a href="%s">log in</a>, and then you can create a new site.', 'theme-my-login'), wp_login_url(Theme_My_Login_Common::get_current_url())); } else { $stage = isset($_POST['stage']) ? $_POST['stage'] : 'default'; switch ($stage) { case 'validate-user-signup': if ($active_signup == 'all' || $_POST['signup_for'] == 'blog' && $active_signup == 'blog' || $_POST['signup_for'] == 'user' && $active_signup == 'user') { $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']); extract($result); $theme_my_login->errors = $errors; if ($errors->get_error_code()) { $this->signup_user($user_name, $user_email); break; } if ('blog' == $_POST['signup_for']) { $this->signup_blog($user_name, $user_email); break; } wpmu_signup_user($user_name, $user_email, apply_filters('add_signup_meta', array())); ?> <h2><?php printf(__('%s is your new username', 'theme-my-login'), $user_name); ?> </h2> <p><?php _e('But, before you can start using your new username, <strong>you must activate it</strong>.', 'theme-my-login'); ?> </p> <p><?php printf(__('Check your inbox at <strong>%1$s</strong> and click the link given.', 'theme-my-login'), $user_email); ?> </p> <p><?php _e('If you do not activate your username within two days, you will have to sign up again.', 'theme-my-login'); ?> </p> <?php do_action('signup_finished'); } else { _e('User registration has been disabled.', 'theme-my-login'); } break; case 'validate-blog-signup': if ($active_signup == 'all' || $active_signup == 'blog') { // Re-validate user info. $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']); extract($result); $theme_my_login->errors = $errors; if ($errors->get_error_code()) { $this->signup_user($user_name, $user_email); break; } $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']); extract($result); $theme_my_login->errors = $errors; if ($errors->get_error_code()) { $this->signup_blog($user_name, $user_email, $blogname, $blog_title); break; } $public = (int) $_POST['blog_public']; $meta = array('lang_id' => 1, 'public' => $public); $meta = apply_filters('add_signup_meta', $meta); wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta); ?> <h2><?php printf(__('Congratulations! Your new site, %s, is almost ready.', 'theme-my-login'), "<a href='http://{$domain}{$path}'>{$blog_title}</a>"); ?> </h2> <p><?php _e('But, before you can start using your site, <strong>you must activate it</strong>.', 'theme-my-login'); ?> </p> <p><?php printf(__('Check your inbox at <strong>%s</strong> and click the link given.', 'theme-my-login'), $user_email); ?> </p> <p><?php _e('If you do not activate your site within two days, you will have to sign up again.', 'theme-my-login'); ?> </p> <h2><?php _e('Still waiting for your email?', 'theme-my-login'); ?> </h2> <p> <?php _e('If you haven’t received your email yet, there are a number of things you can do:', 'theme-my-login'); ?> <ul id="noemail-tips"> <li><p><strong><?php _e('Wait a little longer. Sometimes delivery of email can be delayed by processes outside of our control.', 'theme-my-login'); ?> </strong></p></li> <li><p><?php _e('Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.', 'theme-my-login'); ?> </p></li> <li><?php printf(__('Have you entered your email correctly? You have entered %s, if it’s incorrect, you will not receive your email.', 'theme-my-login'), $user_email); ?> </li> </ul> </p> <?php do_action('signup_finished'); } else { _e('Site registration has been disabled.', 'theme-my-login'); } break; case 'gimmeanotherblog': $current_user = wp_get_current_user(); if (!is_user_logged_in()) { die; } $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $current_user); extract($result); $theme_my_login->errors = $errors; if ($errors->get_error_code()) { $this->signup_another_blog($blogname, $blog_title); break; } $public = (int) $_POST['blog_public']; $meta = apply_filters('signup_create_blog_meta', array('lang_id' => 1, 'public' => $public)); // deprecated $meta = apply_filters('add_signup_meta', $meta); wpmu_create_blog($domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid); ?> <h2><?php printf(__('The site %s is yours.', 'theme-my-login'), "<a href='http://{$domain}{$path}'>{$blog_title}</a>"); ?> </h2> <p> <?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new site. <a href="%3$s">Log in</a> as “%4$s” using your existing password.', 'theme-my-login'), $domain . $path, $domain . $path, "http://" . $domain . $path . "wp-login.php", $current_user->user_login); ?> </p> <?php do_action('signup_finished'); break; case 'default': default: $user_email = isset($_POST['user_email']) ? $_POST['user_email'] : ''; do_action('preprocess_signup_form'); // populate the form from invites, elsewhere? if (is_user_logged_in() && ($active_signup == 'all' || $active_signup == 'blog')) { $this->signup_another_blog($newblogname); } elseif (is_user_logged_in() == false && ($active_signup == 'all' || $active_signup == 'user')) { $this->signup_user($newblogname, $user_email); } elseif (is_user_logged_in() == false && $active_signup == 'blog') { _e('Sorry, new registrations are not allowed at this time.', 'theme-my-login'); } else { _e('You are logged in already. No need to register again!', 'theme-my-login'); } if ($newblogname) { $newblog = get_blogaddress_by_name($newblogname); if ($active_signup == 'blog' || $active_signup == 'all') { printf(__('<p><em>The site you were looking for, <strong>%s</strong> does not exist, but you can create it now!</em></p>', 'theme-my-login'), $newblog); } else { printf(__('<p><em>The site you were looking for, <strong>%s</strong>, does not exist.</em></p>', 'theme-my-login'), $newblog); } } break; } } echo '</div>'; do_action('after_signup_form'); }
private function registerUser() { global $userMeta; /// $userData: array. $userData = apply_filters('user_meta_pre_user_register', $this->userData); if (is_wp_error($userData)) { return $userMeta->showError($userData); } if (is_multisite() && wp_verify_nonce(@$_POST['um_newblog'], 'blogname') && !empty($_POST['blogname'])) { $blogData = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']); if ($blogData['errors']->get_error_code()) { return $userMeta->showError($blogData['errors']); } } // If add_user_to_blog set true in UserMeta settings panel $userID = null; if (is_multisite()) { $registrationSettings = $userMeta->getSettings('registration'); if (!empty($registrationSettings['add_user_to_blog'])) { $user_login = sanitize_user($userData['user_login'], true); $userID = username_exists($user_login); if ($userID) { $blog_id = get_current_blog_id(); if (!is_user_member_of_blog($userID, $blog_id)) { add_user_to_blog($blog_id, $userID, get_option('default_role')); } else { $userID = null; } } } } $response = $userMeta->insertUser($userData, $userID); if (is_wp_error($response)) { return $userMeta->showError($response); } if (isset($blogData)) { $responseBlog = $userMeta->registerBlog($blogData, $userData); if (is_wp_error($responseBlog)) { return $userMeta->showError($responseBlog); } } /// Allow to populate form data based on DB instead of $_REQUEST $userMeta->showDataFromDB = true; $registrationSettings = $userMeta->getSettings('registration'); $activation = $registrationSettings['user_activation']; if ($activation == 'auto_active') { $msg = $userMeta->getMsg('registration_completed'); } elseif ($activation == 'email_verification') { $msg = $userMeta->getMsg('sent_verification_link'); } elseif ($activation == 'admin_approval') { $msg = $userMeta->getMsg('wait_for_admin_approval'); } elseif ($activation == 'both_email_admin') { $msg = $userMeta->getMsg('sent_link_wait_for_admin'); } if (!$userMeta->isPro()) { wp_new_user_notification($response['ID'], $response['user_pass']); } if ($activation == 'auto_active') { if (!empty($registrationSettings['auto_login'])) { $userMeta->doLogin($response); } } do_action('user_meta_after_user_register', (object) $response); $html = $userMeta->showMessage($msg); if (isset($responseBlog)) { $html .= $userMeta->showMessage($responseBlog); } $role = $userMeta->getUserRole($response['ID']); $redirect_to = $userMeta->getRedirectionUrl(null, 'registration', $role); if ($userMeta->isHookEnable('registration_redirect')) { $redirect_to = apply_filters('registration_redirect', $redirect_to, $response['ID']); } if ($redirect_to) { if (empty($_REQUEST['is_ajax'])) { wp_redirect($redirect_to); exit; } $timeout = $activation == 'auto_active' ? 3 : 5; $html .= $userMeta->jsRedirect($redirect_to, $timeout); } $html = "<div action_type=\"registration\">" . $html . "</div>"; return $userMeta->printAjaxOutput($html); }
public static function validate_multisite_submission($form, $config, $pagenum) { global $path; $multisite_options = $config['meta']['multisite_options']; // make sure multisite create site option is set if (empty($multisite_options['create_site'])) { return $form; } // $_POST to Entry $entry = self::convert_post_to_entry(); $domain = ''; $site_address_field = RGFormsModel::get_field($form, $multisite_options['site_address']); $site_address = self::get_prepared_value($site_address_field, $multisite_options['site_address'], $entry); $site_title_field = RGFormsModel::get_field($form, $multisite_options['site_title']); $site_title = self::get_prepared_value($site_title_field, $multisite_options['site_title'], $entry); // get validation result for multi-site fields $validation_result = wpmu_validate_blog_signup($site_address, $site_title, wp_get_current_user()); $error_msg = false; // site address validation, only if on correct page if ($site_address_field['pageNumber'] == $pagenum) { $error_msg = isset($validation_result['errors']->errors['blogname'][0]) ? $validation_result['errors']->errors['blogname'][0] : false; if ($error_msg != false) { $form = self::add_validation_failure($multisite_options['site_address'], $form, $error_msg); } } // site title validation, only if on correct page if ($site_title_field['pageNumber'] == $pagenum) { $error_msg = isset($validation_result['errors']->errors['blog_title'][0]) ? $validation_result['errors']->errors['blog_title'][0] : false; if ($error_msg != false) { $form = self::add_validation_failure($multisite_options['site_title'], $form, $error_msg); } } return $form; }
/** * Validate blog URL and title provided at signup. * * @since 1.2.2 * * @todo Why do we have this wrapper? * * @param string $blog_url Blog URL requested during registration. * @param string $blog_title Blog title requested during registration. * @return array */ function bp_core_validate_blog_signup($blog_url, $blog_title) { if (!is_multisite() || !function_exists('wpmu_validate_blog_signup')) { return false; } /** * Filters the validated blog url and title provided at signup. * * @since 1.2.2 * * @param array $value Array with the new site data and error messages. */ return apply_filters('bp_core_validate_blog_signup', wpmu_validate_blog_signup($blog_url, $blog_title)); }
function bp_core_validate_blog_signup($blog_url, $blog_title) { if (!is_multisite() || !function_exists('wpmu_validate_blog_signup')) { return false; } return apply_filters('bp_core_validate_blog_signup', wpmu_validate_blog_signup($blog_url, $blog_title)); }
/** * Validate new site signup * * @since MU * * @return bool True if the site signup was validated, false if error */ function validate_blog_signup() { // Re-validate user info. $user_result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']); $user_name = $user_result['user_name']; $user_email = $user_result['user_email']; $user_errors = $user_result['errors']; if ($user_errors->get_error_code()) { signup_user($user_name, $user_email, $user_errors); return false; } $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']); $domain = $result['domain']; $path = $result['path']; $blogname = $result['blogname']; $blog_title = $result['blog_title']; $errors = $result['errors']; if ($errors->get_error_code()) { signup_blog($user_name, $user_email, $blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $signup_meta = array('lang_id' => 1, 'public' => $public); // Handle the language setting for the new site. if (!empty($_POST['WPLANG'])) { $languages = signup_get_available_languages(); if (in_array($_POST['WPLANG'], $languages)) { $language = wp_unslash(sanitize_text_field($_POST['WPLANG'])); if ($language) { $signup_meta['WPLANG'] = $language; } } } /** This filter is documented in wp-signup.php */ $meta = apply_filters('add_signup_meta', $signup_meta); wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta); confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta); return true; }
return FALSE; } add_filter('wpmu_signup_blog_notification', 'psu_signup_blog_notification', 11, 7); // we don't want crawlers to index this page, if they ever get here. function signuppageheaders() { echo "<meta name='robots' content='noindex,nofollow' />\n"; } add_action('wp_head', 'signuppageheaders'); // put a header on the page get_header(); /* Set the information about the user and his/her new blog. Make changes here as appropriate for your site. */ $user_email = $username . '@site.org'; /* Set the url for the new blog based on the username returned from CAS. Underscores aren't allowed in MU blog addresses; You may have to clean your usernames in other ways as well. */ $sitename = str_replace('_', '-', $username); /* We can't use the global $domain, it turns out, because it isn't set to the base domain, but to the subdomain of whatever blog the user is currently visiting. */ $domain = $sitename . '.blogs.site.org'; // provision it wpmu_signup_blog($domain, $base, $sitename, $username, $user_email); wpmu_validate_blog_signup();
/** * Registers a new blog signup * * @since MU * * @uses wp_get_current_user() to retrieve the current user * @uses wpmu_validate_blog_signup() to validate site availability * @uses wpmu_create_blog() to add a new site * @return bool Object containing site information or errors object if error */ function register_site() { global $wpdb, $blogname, $blog_title, $errors, $domain, $path; if (!is_user_logged_in()) { $error = new WP_Error(); $error->add('user', __('You must be logged in to create a site.')); return $error; } if (is_array(get_site_option('illegal_names')) && isset($_POST['blogname']) && in_array($_POST['blogname'], get_site_option('illegal_names')) == true) { $error = new WP_Error(); $error->add('illegal_name', __('This site name is not allowed.')); return $error; } $newblogname = isset($_POST['blogname']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_POST['blogname'])) : null; $user = ''; if (is_user_logged_in()) { $user = wp_get_current_user(); } $result = wpmu_validate_blog_signup($newblogname, $_POST['blog_title'], $user); extract($result); if ($errors->get_error_code()) { return $errors; } $public = (int) $_POST['blog_public']; $blog_meta_defaults = array('lang_id' => 1, 'public' => $public); /** * Filter the new site meta variables. * * @since MU * @deprecated 3.0.0 Use the 'add_signup_meta' filter instead. * * @param array $blog_meta_defaults An array of default blog meta variables. */ $meta = apply_filters('signup_create_blog_meta', $blog_meta_defaults); /** * Filter the new default site meta variables. * * @since 3.0.0 * * @param array $meta { * An array of default site meta variables. * * @type int $lang_id The language ID. * @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false. * } */ $meta = apply_filters('add_signup_meta', $meta); $result = wpmu_create_blog($domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid); if ($errors->get_error_code()) { return $errors; } $result = array('blogname' => $newblogname, 'blog_title' => $blog_title); $result = array('status' => 'ok', 'created' => true, 'site' => $result); return $result; }
/** * Redirect user to checkout page after signup * * @param type $blog_id * @param type $user_id * @param type $domain * @param type $path * @param type $site_id * @param type $meta */ function signup_redirect_checkout() { global $wpdb; //If pay before blog is disabled, allow blog activation through email $show_signup = $this->get_setting( 'show_signup' ); if ( 1 != $show_signup ) { return; } if ( ( empty( $_POST['signup_blog_url'] ) && empty( $_POST['blogname'] ) ) || ! isset( $_POST['psts_signed_up'] ) || $_POST['psts_signed_up'] != 'yes' ) { //No post details to check return; } /* Remove confirmation text between filter and action, this could be removed if confirm_blog_signup gets a filter */ ob_get_clean(); $blogname = ! empty( $_POST['blogname'] ) ? $_POST['blogname'] : ( ! empty( $_POST['signup_blog_url'] ) ? $_POST['signup_blog_url'] : '' ); $blogtitle = ! empty( $_POST['blog_title'] ) ? $_POST['blog_title'] : ( ! empty( $_POST['signup_blog_title'] ) ? $_POST['signup_blog_title'] : '' ); $blog_details = wpmu_validate_blog_signup( $blogname, $blogtitle ); if ( empty( $blog_details ['domain'] ) ) { return; } $domain = $blog_details['domain']; //Check if blog is in trial or inactive, set session values and redirect to checkout page $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s", $domain ) ); if ( ! $signup->active ) { ProSites_Helper_Session::session( 'domain', $domain ); ProSites_Helper_Session::session( 'meta', $signup->meta ); ?> <!--redirect to checkout url--> <script type="text/javascript"> window.location = '<?php echo $this->checkout_url(); ?>'; </script><?php } return; }
public static function ajax_check_prosite_blog() { global $psts, $current_site; $blog_data = array(); // Add ajax session var ProSites_Helper_Session::session('psts_ajax_session_activated', true); // Introduce a fake error because we don't want to actually create the blog yet. add_filter('registration_errors', array('ProSites_Model_Registration', 'prosite_blog_check_only'), 10, 3); // replace $_POST with array data $params = array(); parse_str($_POST['data'], $params); $period = (int) $_POST['period']; $level = 'free' == $_POST['level'] ? $_POST['level'] : (int) $_POST['level']; $_POST = $params; $doing_ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false; $ajax_response = array(); if ($doing_ajax) { $user_name = sanitize_text_field($_POST['user_name']); $user_email = sanitize_email($_POST['user_email']); $blogname = sanitize_text_field($_POST['blogname']); $blog_title = sanitize_text_field(urldecode($_POST['blog_title'])); // Process some cleaning up if needed do_action('prosite_register_blog_pre_validation', $user_name, $user_email, $blogname); $blog_validation = wpmu_validate_blog_signup($blogname, $blog_title); // Attempt to create a new user (knowing that it will fail, but it should only have our error) if (!isset($_POST['new_blog'])) { $validation = wpmu_validate_user_signup($user_name, $user_email); // nicer errors, but doesn't deal with custom fields $user_check = register_new_user($user_name, $user_email); // checks custom fields, but ugly errors $user_check->errors = array_merge($user_check->errors, $validation['errors']->errors); $user_check->errors = array_merge($user_check->errors, $blog_validation['errors']->errors); } else { $user_check = new WP_Error(); $user_check->errors = array_merge($user_check->errors, $blog_validation['errors']->errors); } // Replaced session vars to make it semi-stateless, will pick these up in a session later $blog_data['new_blog_details'] = array(); $blog_data['new_blog_details']['username'] = $user_name; $blog_data['new_blog_details']['email'] = $user_email; $blog_data['new_blog_details']['blogname'] = $blogname; $blog_data['new_blog_details']['title'] = $blog_title; $blog_data['new_blog_details']['level'] = $level; $blog_data['new_blog_details']['period'] = $period; $username_available = true; $email_available = true; $blogname_available = true; $blogtitle_available = true; // Checking passed... if (!empty($user_check->errors) && 1 == count($user_check->errors) && !isset($_POST['new_blog']) || 0 == count($user_check->errors) && isset($_POST['new_blog'])) { $keys = array_keys($user_check->errors); if ($keys && !in_array('availability_check_only', $keys) && !isset($_POST['new_blog'])) { // Something went wrong! $ajax_response['user_available'] = false; } else { // All good! We're ready to create the user/site /** User is validated using register_new_user so that we can use the hooks and make them available, * but we still need to actually create and activate the signup to get the $user_id. */ $blog = $blog_validation; $domain = $blog['domain']; $path = $blog['path']; $blogname = $blog['blogname']; $blog_title = $blog['blog_title']; $errors = $blog['errors']; // Privacy setting $public = (int) $_POST['blog_public']; $signup_meta = array('lang_id' => 1, 'public' => $public); // Create the signup $meta = apply_filters('add_signup_meta', $signup_meta); $result = ProSites_Helper_Registration::signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta); $blog_data['activation_key'] = $result['activation_key']; if (isset($result['user_pass']) && !empty($result['user_pass'])) { $blog_data['new_blog_details']['user_pass'] = $result['user_pass']; } $trial_days = $psts->get_setting('trial_days', 0); $trial_active = !empty($trial_days); $site_name = ''; if (!is_subdomain_install()) { $site_name = $current_site->domain . $current_site->path . $blogname; } else { $site_name = $blogname . '.' . ($site_domain = preg_replace('|^www\\.|', '', $current_site->domain)); } if ($trial_active) { $recurring = $psts->get_setting('recurring_subscriptions', 1); if ($recurring) { $blog_data['new_blog_details']['reserved_message'] = sprintf('<div class="reserved_msg"><h2>' . __('Activate your site', 'psts') . '</h2>' . __('<p>Your site <strong>(%s)</strong> has been reserved but is not yet activated.</p><p>Once payment information has been verified your trial period will begin. When your trial ends you will be automatically upgraded to your chosen plan. Your reservation only last for 48 hours upon which your site name will become available again.</p><p>Please use the form below to setup your payment information.</p>', 'psts') . '</div>', $site_name); } else { // Non-recurring sites really should not do anything at checkout other than activate. $result = ProSites_Helper_Registration::activate_blog($blog_data, true, $period, $level); $blog_id = $result['blog_id']; if (isset($result['password'])) { $blog_data['new_blog_details']['user_pass'] = $result['password']; } ProSites_Helper_Registration::set_trial($blog_id, 1); //Update Activation Key for blog ProSites_Helper_Registration::update_activation_key($blog_id, $blog_data['activation_key']); $psts->record_stat($blog_id, 'signup'); $ajax_response['show_finish'] = true; $ajax_response['finish_content'] = ProSites_View_Front_Gateway::render_payment_submitted($blog_data, true); } } else { $blog_data['new_blog_details']['reserved_message'] = sprintf('<div class="reserved_msg"><h2>' . __('Activate your site', 'psts') . '</h2>' . __('<p>Your site <strong>(%s)</strong> has been reserved but is not yet activated.</p><p>Once payment has been processed your site will become active with your chosen plan. Your reservation only last for 48 hours upon which your site name will become available again.</p><p>Please use the form below to setup your payment information.</p>', 'psts') . '</div>', $site_name); } // FREE basic site if ('free' == $blog_data['new_blog_details']['level']) { if (isset($blog_data['new_blog_details']['reserved_message'])) { unset($blog_data['new_blog_details']['reserved_message']); } $result = ProSites_Helper_Registration::activate_blog($blog_data, false, false, false); $blog_data['new_blog_details']['blog_id'] = $result['blog_id']; if (isset($result['password'])) { $blog_data['new_blog_details']['user_pass'] = $result['password']; } $ajax_response['show_finish'] = true; $ajax_response['finish_content'] = ProSites_View_Front_Gateway::render_free_confirmation($blog_data); } if (isset($blog_data['new_blog_details']['reserved_message'])) { $ajax_response['reserved_message'] = $blog_data['new_blog_details']['reserved_message']; } } // If WP 4.0+ and user is logged in it will use WP_Session_Tokens, else $_SESSION ProSites_Helper_Session::session('new_blog_details', $blog_data['new_blog_details']); ProSites_Helper_Session::session('activation_key', $blog_data['activation_key']); $ajax_response['gateways_form'] = ProSites_View_Front_Gateway::render_checkout($blog_data); } else { // We had registration errors, redraw the form displaying errors if (!empty($user_check) && isset($user_check->errors)) { $ajax_response['form'] = ProSites_View_Front_Registration::render_signup_form($blog_data, $user_check); $ajax_response['user_available'] = false; } // Isolate which standard fields are valid $error_keys = array_keys($user_check->errors); foreach ($error_keys as $key) { if (preg_match('/username|user_name/', $key)) { $username_available = false; } if (preg_match('/email/', $key)) { $email_available = false; } if (preg_match('/blogname/', $key)) { $blogname_available = false; } if (preg_match('/blog_title/', $key)) { $blogtitle_available = false; } } } $ajax_response['username_available'] = $username_available; $ajax_response['email_available'] = $email_available; $ajax_response['blogname_available'] = $blogname_available; $ajax_response['blog_title_available'] = $blogtitle_available; $response = array('what' => 'response', 'action' => 'check_prosite_blog', 'id' => 1, 'data' => json_encode($ajax_response)); // No longer need ajax session ProSites_Helper_Session::unset_session('psts_ajax_session_activated'); // Buffer used to isolate AJAX response from unexpected output @ob_end_clean(); ob_start(); $xmlResponse = new WP_Ajax_Response($response); $xmlResponse->send(); ob_end_flush(); } }
* @package WooFramework * @subpackage Template */ session_start(); if (isset($_SESSION["agent_no"])) { $agent_no = $_SESSION["agent_no"]; } else { wp_redirect("step1"); exit; } if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { if ($_POST['create-web-confirm'] != 1) { $error_message = "<li>กรุณาติ๊กเพื่อยืนยันในการสร้างเว็บไซต์ส่วนตัวของคุณ และกดบันทึกข้อมูล</li>"; } else { $_POST['blog'] = array("email" => $_SESSION["agent-email"], "domain" => $_SESSION['site-url'], "title" => '' . $_SESSION['site-url'] . '- by Srikrung'); wpmu_validate_blog_signup($_POST['blog']['domain'], $_POST['blog']['title']); update_agent_info($_SESSION); create_microweb(); $_SESSION['create-web-finish'] = true; wp_redirect("step-finish"); exit; } } function update_agent_info($agent_data) { $agent = get_user_from_agent_no($agent_data["agent_no"]); $user_id = $agent->ID; if ($user_id) { $user_id = wp_update_user(array("ID" => $user_id, "user_email" => $agent_data['agent-email'])); // update agent user meta data. update_user_meta($user_id, "agent-first", $agent_data['agent-first']);
function wpmu_activate_signup($key) { global $wpdb; $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $key)); if (empty($signup)) { return new WP_Error('invalid_key', __('Invalid activation key.')); } if ($signup->active) { return new WP_Error('already_active', __('The blog is already active.'), $signup); } $meta = unserialize($signup->meta); $user_login = $wpdb->escape($signup->user_login); $user_email = $wpdb->escape($signup->user_email); wpmu_validate_user_signup($user_login, $user_email); $password = generate_random_password(); $user_id = username_exists($user_login); if (!$user_id) { $user_id = wpmu_create_user($user_login, $password, $user_email); } else { $user_already_exists = true; } if (!$user_id) { return new WP_Error('create_user', __('Could not create user'), $signup); } $now = current_time('mysql', true); if (empty($signup->domain)) { $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); if (isset($user_already_exists)) { return new WP_Error('user_already_exists', __('That username is already activated.'), $signup); } wpmu_welcome_user_notification($user_id, $password, $meta); if (get_site_option('dashboard_blog') == false) { add_user_to_blog('1', $user_id, get_site_option('default_user_role', 'subscriber')); } else { add_user_to_blog(get_site_option('dashboard_blog'), $user_id, get_site_option('default_user_role', 'subscriber')); } add_new_user_to_blog($user_id, $user_email, $meta); do_action('wpmu_activate_user', $user_id, $password, $meta); return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta); } wpmu_validate_blog_signup($signup->domain, $signup->title); $blog_id = wpmu_create_blog($signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid); // TODO: What to do if we create a user but cannot create a blog? if (is_wp_error($blog_id)) { // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and // setting the activation flag. Let's just set the active flag and instruct the user to reset their password. if ('blog_taken' == $blog_id->get_error_code()) { $blog_id->add_data($signup); $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); } return $blog_id; } $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta); do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta); return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); }
private function generate_new_blogid() { $blog_title = __('Migrated site (from UpdraftPlus)', 'updraftplus'); if (empty($_POST['updraftplus_migrate_blogname'])) { $this->getinfo_form(); return false; } // Verify value given $result = wpmu_validate_blog_signup($_POST['updraftplus_migrate_blogname'], $blog_title); if (count($result['errors']) > 0 && $result['errors']->get_error_code()) { if (is_wp_error($result['errors'])) { $err_msg = '<ul style="list-style: disc inside;">'; foreach ($result['errors']->get_error_messages() as $key => $msg) { $err_msg .= '<li><strong>' . __('Error:', 'updraftplus') . '</strong> ' . htmlspecialchars($msg) . '</li>'; } $err_msg .= '</ul>'; } if (isset($err_msg)) { $this->getinfo_form($err_msg, $_POST['updraftplus_migrate_blogname']); return false; } } $blogname = $_POST['updraftplus_migrate_blogname']; global $wpdb; if (domain_exists($result['domain'], $result['path'], $wpdb->siteid)) { // A WordPress-native string $this->getinfo_form(__('<strong>ERROR</strong>: Site URL already taken.'), $_POST['updraftplus_migrate_blogname']); return false; } $create = create_empty_blog($result['domain'], $result['path'], $blog_title, $wpdb->siteid); if (is_integer($create)) { $url = untrailingslashit($result['domain'] . $result['path']); echo '<strong>' . __('New site:', 'updraftplus') . '</strong> ' . $url . '<br>'; // Update record of what we want to rewrite the URLs to in the search/replace operation // TODO: How to detect whether http or https??? $this->siteurl = 'http://' . $url; // ??? $this->home = 'http://' . $url; return $create; } else { $this->getinfo_form(print_r($create, true), $_POST['updraftplus_migrate_blogname']); return false; } }
printf(__('This host\'s memory_limit is set to %dMB - we generally recommend at least 128MB for running the Cloner. You may want to increase the memory_limit in php.ini (or wherever your host supports PHP configuration updates) to avoid any out-of-memory errors.', 'ns-cloner'), $memory_limit); echo "</span>"; } // warn if .htaccess does not contain multisite file rewrite (but only if not on iis7) if (!iis7_supports_permalinks()) { // foolproof htaccess path detection stolen from wp-admin/includes/network.php $slashed_home = trailingslashit(get_option('home')); $base = parse_url($slashed_home, PHP_URL_PATH); $document_root_fix = str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT'])); $abspath_fix = str_replace('\\', '/', ABSPATH); $home_path = 0 === strpos($abspath_fix, $document_root_fix) ? $document_root_fix . $base : get_home_path(); $htaccess = file_get_contents($home_path . '.htaccess'); // set patterns which tell us that multisite file rewrite is there $pre_3_5_rewrite = 'wp-includes/ms-files.php'; $post_3_5_rewrite = '(wp-(content|admin|includes)'; // show error if neither pattern occurs if (strpos($htaccess, $pre_3_5_rewrite) === false && strpos($htaccess, $post_3_5_rewrite) === false) { echo "<span class='ns-cloner-warning-message'>"; printf(__('It appears that you have a non-standard (possibly incorrect) .htaccess file for a multisite install. Cloned sites will not work if rewrites are not configured correctly. Please check the recommended htaccess settings <a href="%s" target="_blank">here</a> and make sure your .htaccess file matches.', 'ns-cloner'), admin_url('/network/setup.php')); echo "</span>"; } } // warn if other plugin installed that adds additional wpmu_validate_blog_signup requirements (like Site Templates) $test_blog_validation = wpmu_validate_blog_signup('nsclonervalidationtest', 'NS Cloner Test'); $errors = $test_blog_validation['errors']->get_error_messages(); if (!empty($errors)) { $errors_string = '"' . join('","', $errors) . '"'; echo "<span class='ns-cloner-warning-message'>"; _e('It looks like you have another plugin installed which is applying its own additional site-meta creation requirements. The Cloner will still work, but you should be aware that sites created with the Cloner might not appear normally in the other plugin.', 'ns-cloner'); echo "</span>"; }
/** * Validate a blog creation submission. * * Essentially, a wrapper for {@link wpmu_validate_blog_signup()}. * * @return array Contains the new site data and error messages. */ function bp_blogs_validate_blog_form() { $user = ''; if (is_user_logged_in()) { $user = wp_get_current_user(); } return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user); }
public function rpr_preprocess_signup_form() { global $active_signup, $stage; switch ($stage) { case 'user-signup': if ($active_signup == 'all' || $_POST['signup_for'] == 'blog' && $active_signup == 'blog' || $_POST['signup_for'] == 'user' && $active_signup == 'user') { /* begin validate_user_signup stage */ // validate signup form, do wpmu_validate_user_signup action $result = wpmu_validate_user_signup(isset($_POST['user_name']) ? (string) $_POST['user_name'] : "", isset($_POST['user_email']) ? (string) $_POST['user_email'] : ""); extract($result); if ($errors->get_error_code()) { echo "signup_user"; signup_user($user_name, $user_email, $errors); do_action('after_signup_form'); get_footer(); exit; } if ('blog' === $_POST['signup_for']) { echo "signup_blog"; signup_blog($user_name, $user_email); do_action('after_signup_form'); get_footer(); exit; } // collect meta, commit user to database, send email wpmu_signup_user($user_name, $user_email, apply_filters('add_signup_meta', array())); // previously, displayed confirm_user_signup message before signup_finished action do_action('signup_finished'); /* end validate_user_signup stage */ } else { _e('User registration has been disabled.'); ?> </div> </div> <?php do_action('after_signup_form'); get_footer(); exit; } break; case 'blog-signup': if ($active_signup == 'all' || $active_signup == 'blog') { /* begin validate_blog_signup stage */ $result = wpmu_validate_user_signup(isset($_POST['user_name']) ? (string) $_POST['user_name'] : "", isset($_POST['user_email']) ? (string) $_POST['user_email'] : ""); extract($result); if ($errors->get_error_code()) { echo "signup_user"; signup_user($user_name, $user_email, $errors); do_action('after_signup_form'); get_footer(); exit; } $result = wpmu_validate_blog_signup(isset($_POST['blogname']) ? (string) $_POST['blogname'] : "", isset($_POST['blog_title']) ? (string) $_POST['blog_title'] : ""); extract($result); if ($errors->get_error_code()) { signup_blog($user_name, $user_email, $blogname, $blog_title, $errors); do_action('after_signup_form'); get_footer(); exit; } // collect meta, commit user to database, send email $meta = array('lang_id' => 1, 'public' => (int) $_POST['blog_public']); wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, apply_filters('add_signup_meta', $meta)); // previously, displayed confirm_blog_signup message before signup_finished action do_action('signup_finished'); /* end validate_blog_signup stage */ } else { _e('Site registration has been disabled.'); ?> </div> </div> <?php do_action('after_signup_form'); get_footer(); exit; } break; default: return; } /* begin wp-activate page */ $key = (string) $_REQUEST['key']; // wpmu_create_user, wpmu_welcome_user_notification, add_new_user_to_blog, do wpmu_activate_user action $result = wpmu_activate_signup($key); if (is_wp_error($result)) { if ('already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code()) { $signup = $result->get_error_data(); ?> <h2><?php _e('Your account is now active!'); ?> </h2> <?php echo '<p class="lead-in">'; if ($signup->domain . $signup->path == '') { printf(__('Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.'), network_site_url('wp-login.php', 'login'), $signup->user_login, $signup->user_email, wp_lostpassword_url()); } else { printf(__('Your site at <a href="%1$s">%2$s</a> is active. You may now log in to your site using your chosen username of “%3$s”. Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%5$s">reset your password</a>.'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, wp_lostpassword_url()); } echo '</p>'; } else { ?> <h2><?php _e('An error occurred during the activation'); ?> </h2> <?php echo '<p>' . $result->get_error_message() . '</p>'; } } else { //TODO: Why not reference $result->blog_id? extract($result); if (isset($blog_id)) { $url = get_blogaddress_by_id((int) $blog_id); } $user = get_userdata((int) $user_id); ?> <h2><?php _e('Your account is now active!'); ?> </h2> <div id="signup-welcome"> <p><span class="h3"><?php _e('Username:'******'Password:'******'', 'http')) { ?> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Log in</a>'), $url, $url . 'wp-login.php'); ?> </p> <?php } else { ?> <p class="view"><?php printf(__('Your account is now activated. <a href="%1$s">Log in</a> or go back to the <a href="%2$s">homepage</a>.'), network_site_url('wp-login.php', 'login'), network_home_url()); ?> </p> <?php } } ?> </div> <script type="text/javascript"> var key_input = document.getElementById('key'); key_input && key_input.focus(); </script> <?php get_footer(); ?> <?php exit; }
/** * Validate new site signup * * @since MU * * @uses wpmu_validate_user_signup() to retrieve an array of the new user data and errors * @uses wpmu_validate_blog_signup() to retrieve an array of the new site data and errors * @uses apply_filters() to make signup $meta filterable * @uses signup_user() to signup a new user * @uses signup_blog() to signup a the new user to a new site * @return bool True if the site signup was validated, false if error */ function validate_blog_signup() { // Re-validate user info. $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']); extract($result); if ($errors->get_error_code()) { signup_user($user_name, $user_email, $errors); return false; } $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']); extract($result); if ($errors->get_error_code()) { signup_blog($user_name, $user_email, $blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $meta = array('lang_id' => 1, 'public' => $public); //duplicate_hook $meta = apply_filters('add_signup_meta', $meta); wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta); confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta); return true; }
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; }
/** * Validate new site signup * * @since MU * * @return bool True if the site signup was validated, false if error */ function validate_blog_signup() { // Re-validate user info. $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] ); $user_name = $user_result['user_name']; $user_email = $user_result['user_email']; $user_errors = $user_result['errors']; if ( $user_errors->get_error_code() ) { signup_user( $user_name, $user_email, $user_errors ); return false; } $result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] ); $domain = $result['domain']; $path = $result['path']; $blogname = $result['blogname']; $blog_title = $result['blog_title']; $errors = $result['errors']; if ( $errors->get_error_code() ) { signup_blog($user_name, $user_email, $blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $signup_meta = array ('lang_id' => 1, 'public' => $public); /** This filter is documented in wp-signup.php */ $meta = apply_filters( 'add_signup_meta', $signup_meta ); wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta); confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta); return true; }
/** * Catch Registry requests and process */ function thatcamp_catch_registry_form() { if (!is_user_logged_in()) { return; } if (empty($_POST['thatcamp-register-submit'])) { return; } // honeypot check if (!empty($_POST['thatcamp-zip-code'])) { return; } // check required fields and fall through if necessary $required_fields = array('thatcamp-name', 'site-url', 'i-agree'); $errors = array(); foreach ($required_fields as $required_field) { if (empty($_POST[$required_field])) { $errors[$required_field] = 'This field is required.'; } // special case for i-agree checkboxes if (!is_array($_POST['i-agree']) || count($_POST['i-agree']) < 5) { $errors['i-agree'] = 'You must agree to all conditions to create a THATCamp.'; } } // Validate URL $validate_blog = wpmu_validate_blog_signup($_POST['site-url'], $_POST['thatcamp-name']); if (!empty($validate_blog['errors']->errors)) { // grab the first one $errors['site-url'] = $validate_blog['errors']->get_error_message(); } if (!empty($errors)) { // Hackville $_POST['errors'] = $errors; return; } // If we've gotten here, go ahead with the registration // @todo We'll use the current user ID for now $meta = array('public' => '1'); $blog_id = wpmu_create_blog($validate_blog['domain'], $validate_blog['path'], $validate_blog['blog_title'], get_current_user_id(), $meta); $group_id = thatcamp_get_blog_group($blog_id); if (!empty($_POST['Country'])) { groups_update_groupmeta($group_id, 'thatcamp_country', $_POST['Country']); } if (!empty($_POST['State'])) { groups_update_groupmeta($group_id, 'thatcamp_state', $_POST['State']); } if (!empty($_POST['Province'])) { groups_update_groupmeta($group_id, 'thatcamp_province', $_POST['Province']); } if (!empty($_POST['City'])) { groups_update_groupmeta($group_id, 'thatcamp_city', $_POST['City']); } groups_update_groupmeta($group_id, 'thatcamp_start_date', strtotime($_POST['thatcamp-start-date'])); groups_update_groupmeta($group_id, 'thatcamp_end_date', strtotime($_POST['thatcamp-end-date'])); // This is the value used for filtering in directories groups_update_groupmeta($group_id, 'thatcamp_date', strtotime($_POST['thatcamp-start-date'])); // Redirect back to the register page, with a success message remove_action('template_redirect', 'redirect_to_mapped_domain'); $redirect_to = add_query_arg('success', urlencode($validate_blog['blogname']), wp_guess_url()); wp_redirect($redirect_to); }