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;
}
/**
* 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));
}
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;
}
开发者ID:andreiRS,项目名称:Radii8,代码行数:65,代码来源:user.php
示例12: signup_redirect_checkout
/**
* 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);
}
//.........这里部分代码省略.........
请发表评论