wp/wp-signup.php
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php
       
     2 
       
     3 /** Sets up the WordPress Environment. */
       
     4 require( dirname(__FILE__) . '/wp-load.php' );
       
     5 
       
     6 add_action( 'wp_head', 'wp_no_robots' );
       
     7 
       
     8 require( dirname( __FILE__ ) . '/wp-blog-header.php' );
       
     9 
       
    10 if ( is_array( get_site_option( 'illegal_names' )) && isset( $_GET[ 'new' ] ) && in_array( $_GET[ 'new' ], get_site_option( 'illegal_names' ) ) == true ) {
       
    11 	wp_redirect( network_home_url() );
       
    12 	die();
       
    13 }
       
    14 
       
    15 /**
       
    16  * Prints signup_header via wp_head
       
    17  *
       
    18  * @since MU
       
    19  */
       
    20 function do_signup_header() {
       
    21 	/**
       
    22 	 * Fires within the <head> section of the site sign-up screen.
       
    23 	 *
       
    24 	 * @since 3.0.0
       
    25 	 */
       
    26 	do_action( 'signup_header' );
       
    27 }
       
    28 add_action( 'wp_head', 'do_signup_header' );
       
    29 
       
    30 if ( !is_multisite() ) {
       
    31 	wp_redirect( site_url('wp-login.php?action=register') );
       
    32 	die();
       
    33 }
       
    34 
       
    35 if ( !is_main_site() ) {
       
    36 	wp_redirect( network_site_url( 'wp-signup.php' ) );
       
    37 	die();
       
    38 }
       
    39 
       
    40 // Fix for page title
       
    41 $wp_query->is_404 = false;
       
    42 
       
    43 /**
       
    44  * Prints styles for front-end Multisite signup pages
       
    45  *
       
    46  * @since MU
       
    47  */
       
    48 function wpmu_signup_stylesheet() {
       
    49 	?>
       
    50 	<style type="text/css">
       
    51 		.mu_register { width: 90%; margin:0 auto; }
       
    52 		.mu_register form { margin-top: 2em; }
       
    53 		.mu_register .error { font-weight:700; padding:10px; color:#333333; background:#FFEBE8; border:1px solid #CC0000; }
       
    54 		.mu_register input[type="submit"],
       
    55 			.mu_register #blog_title,
       
    56 			.mu_register #user_email,
       
    57 			.mu_register #blogname,
       
    58 			.mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }
       
    59 		.mu_register .prefix_address,
       
    60 			.mu_register .suffix_address {font-size: 18px;display:inline; }
       
    61 		.mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
       
    62 		.mu_register label.checkbox { display:inline; }
       
    63 		.mu_register .mu_alert { font-weight:700; padding:10px; color:#333333; background:#ffffe0; border:1px solid #e6db55; }
       
    64 	</style>
       
    65 	<?php
       
    66 }
       
    67 
       
    68 add_action( 'wp_head', 'wpmu_signup_stylesheet' );
       
    69 get_header();
       
    70 
       
    71 /**
       
    72  * Fires before the site sign-up form.
       
    73  *
       
    74  * @since 3.0.0
       
    75  */
       
    76 do_action( 'before_signup_form' );
       
    77 ?>
       
    78 <div id="content" class="widecolumn">
       
    79 <div class="mu_register">
       
    80 <?php
       
    81 /**
       
    82  * Generates and displays the Signup and Create Site forms
       
    83  *
       
    84  * @since MU
       
    85  *
       
    86  * @param string $blogname The new site name
       
    87  * @param string $blog_title The new site title
       
    88  * @param array $errors
       
    89  */
       
    90 function show_blog_form($blogname = '', $blog_title = '', $errors = '') {
       
    91 	global $current_site;
       
    92 	// Blog name
       
    93 	if ( !is_subdomain_install() )
       
    94 		echo '<label for="blogname">' . __('Site Name:') . '</label>';
       
    95 	else
       
    96 		echo '<label for="blogname">' . __('Site Domain:') . '</label>';
       
    97 
       
    98 	if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
       
    99 		<p class="error"><?php echo $errmsg ?></p>
       
   100 	<?php }
       
   101 
       
   102 	if ( !is_subdomain_install() )
       
   103 		echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'. esc_attr($blogname) .'" maxlength="60" /><br />';
       
   104 	else
       
   105 		echo '<input name="blogname" type="text" id="blogname" value="'.esc_attr($blogname).'" maxlength="60" /><span class="suffix_address">.' . ( $site_domain = preg_replace( '|^www\.|', '', $current_site->domain ) ) . '</span><br />';
       
   106 
       
   107 	if ( !is_user_logged_in() ) {
       
   108 		if ( !is_subdomain_install() )
       
   109 			$site = $current_site->domain . $current_site->path . __( 'sitename' );
       
   110 		else
       
   111 			$site = __( 'domain' ) . '.' . $site_domain . $current_site->path;
       
   112 		echo '<p>(<strong>' . sprintf( __('Your address will be %s.'), $site ) . '</strong>) ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!' ) . '</p>';
       
   113 	}
       
   114 
       
   115 	// Blog Title
       
   116 	?>
       
   117 	<label for="blog_title"><?php _e('Site Title:') ?></label>
       
   118 	<?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
       
   119 		<p class="error"><?php echo $errmsg ?></p>
       
   120 	<?php }
       
   121 	echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />';
       
   122 	?>
       
   123 
       
   124 	<div id="privacy">
       
   125         <p class="privacy-intro">
       
   126             <label for="blog_public_on"><?php _e('Privacy:') ?></label>
       
   127             <?php _e( 'Allow search engines to index this site.' ); ?>
       
   128             <br style="clear:both" />
       
   129             <label class="checkbox" for="blog_public_on">
       
   130                 <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if ( !isset( $_POST['blog_public'] ) || $_POST['blog_public'] == '1' ) { ?>checked="checked"<?php } ?> />
       
   131                 <strong><?php _e( 'Yes' ); ?></strong>
       
   132             </label>
       
   133             <label class="checkbox" for="blog_public_off">
       
   134                 <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if ( isset( $_POST['blog_public'] ) && $_POST['blog_public'] == '0' ) { ?>checked="checked"<?php } ?> />
       
   135                 <strong><?php _e( 'No' ); ?></strong>
       
   136             </label>
       
   137         </p>
       
   138 	</div>
       
   139 
       
   140 	<?php
       
   141 	/**
       
   142 	 * Fires after the site sign-up form.
       
   143 	 *
       
   144 	 * @since 3.0.0
       
   145 	 *
       
   146 	 * @param array $errors An array possibly containing 'blogname' or 'blog_title' errors.
       
   147 	 */
       
   148 	do_action( 'signup_blogform', $errors );
       
   149 }
       
   150 
       
   151 /**
       
   152  * Validate the new site signup
       
   153  *
       
   154  * @since MU
       
   155  *
       
   156  * @uses wp_get_current_user() to retrieve the current user
       
   157  * @uses wpmu_validate_blog_signup() to validate new site signup for the current user
       
   158  * @return array Contains the new site data and error messages.
       
   159  */
       
   160 function validate_blog_form() {
       
   161 	$user = '';
       
   162 	if ( is_user_logged_in() )
       
   163 		$user = wp_get_current_user();
       
   164 
       
   165 	return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
       
   166 }
       
   167 
       
   168 /**
       
   169  * Display user registration form
       
   170  *
       
   171  * @since MU
       
   172  *
       
   173  * @param string $user_name The entered username
       
   174  * @param string $user_email The entered email address
       
   175  * @param array $errors
       
   176  */
       
   177 function show_user_form($user_name = '', $user_email = '', $errors = '') {
       
   178 	// User name
       
   179 	echo '<label for="user_name">' . __('Username:') . '</label>';
       
   180 	if ( $errmsg = $errors->get_error_message('user_name') ) {
       
   181 		echo '<p class="error">'.$errmsg.'</p>';
       
   182 	}
       
   183 	echo '<input name="user_name" type="text" id="user_name" value="'. esc_attr($user_name) .'" maxlength="60" /><br />';
       
   184 	_e( '(Must be at least 4 characters, letters and numbers only.)' );
       
   185 	?>
       
   186 
       
   187 	<label for="user_email"><?php _e( 'Email&nbsp;Address:' ) ?></label>
       
   188 	<?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
       
   189 		<p class="error"><?php echo $errmsg ?></p>
       
   190 	<?php } ?>
       
   191 	<input name="user_email" type="text" id="user_email" value="<?php  echo esc_attr($user_email) ?>" maxlength="200" /><br /><?php _e('We send your registration email to this address. (Double-check your email address before continuing.)') ?>
       
   192 	<?php
       
   193 	if ( $errmsg = $errors->get_error_message('generic') ) {
       
   194 		echo '<p class="error">' . $errmsg . '</p>';
       
   195 	}
       
   196 	/**
       
   197 	 * Fires at the end of the user registration form on the site sign-up form.
       
   198 	 *
       
   199 	 * @since 3.0.0
       
   200 	 *
       
   201 	 * @param array $errors An array possibly containing 'user_name' or 'user_email' errors.
       
   202 	 */
       
   203 	do_action( 'signup_extra_fields', $errors );
       
   204 }
       
   205 
       
   206 /**
       
   207  * Validate user signup name and email
       
   208  *
       
   209  * @since MU
       
   210  *
       
   211  * @uses wpmu_validate_user_signup() to retrieve an array of user data
       
   212  * @return array Contains username, email, and error messages.
       
   213  */
       
   214 function validate_user_form() {
       
   215 	return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
       
   216 }
       
   217 
       
   218 /**
       
   219  * Allow returning users to sign up for another site
       
   220  *
       
   221  * @since MU
       
   222  *
       
   223  * @uses wp_get_current_user() to get the current user
       
   224  * @param string $blogname The new site name
       
   225  * @param string $blog_title The new blog title
       
   226  * @param array $errors
       
   227  */
       
   228 function signup_another_blog($blogname = '', $blog_title = '', $errors = '') {
       
   229 	global $current_site;
       
   230 	$current_user = wp_get_current_user();
       
   231 
       
   232 	if ( ! is_wp_error($errors) ) {
       
   233 		$errors = new WP_Error();
       
   234 	}
       
   235 
       
   236 	$signup_defaults = array(
       
   237 		'blogname'   => $blogname,
       
   238 		'blog_title' => $blog_title,
       
   239 		'errors'     => $errors
       
   240 	);
       
   241 
       
   242 	/**
       
   243 	 * Filter the default site sign-up variables.
       
   244 	 *
       
   245 	 * @since 3.0.0
       
   246 	 *
       
   247 	 * @param array $signup_defaults {
       
   248 	 *     An array of default site sign-up variables.
       
   249 	 *
       
   250 	 *     @type string $blogname   The site blogname.
       
   251 	 *     @type string $blog_title The site title.
       
   252 	 *     @type array  $errors     An array possibly containing 'blogname' or 'blog_title' errors.
       
   253 	 * }
       
   254 	 */
       
   255 	$filtered_results = apply_filters( 'signup_another_blog_init', $signup_defaults );
       
   256 
       
   257 	$blogname = $filtered_results['blogname'];
       
   258 	$blog_title = $filtered_results['blog_title'];
       
   259 	$errors = $filtered_results['errors'];
       
   260 
       
   261 	echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), $current_site->site_name ) . '</h2>';
       
   262 
       
   263 	if ( $errors->get_error_code() ) {
       
   264 		echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
       
   265 	}
       
   266 	?>
       
   267 	<p><?php printf( __( 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. There is no limit to the number of sites you can have, so create to your heart&#8217;s content, but write responsibly!' ), $current_user->display_name ) ?></p>
       
   268 
       
   269 	<?php
       
   270 	$blogs = get_blogs_of_user($current_user->ID);
       
   271 	if ( !empty($blogs) ) { ?>
       
   272 
       
   273 			<p><?php _e( 'Sites you are already a member of:' ) ?></p>
       
   274 			<ul>
       
   275 				<?php foreach ( $blogs as $blog ) {
       
   276 					$home_url = get_home_url( $blog->userblog_id );
       
   277 					echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
       
   278 				} ?>
       
   279 			</ul>
       
   280 	<?php } ?>
       
   281 
       
   282 	<p><?php _e( 'If you&#8217;re not going to use a great site domain, leave it for a new user. Now have at it!' ) ?></p>
       
   283 	<form id="setupform" method="post" action="wp-signup.php">
       
   284 		<input type="hidden" name="stage" value="gimmeanotherblog" />
       
   285 		<?php
       
   286 		/**
       
   287 		 * Hidden sign-up form fields output when creating another site or user.
       
   288 		 *
       
   289 		 * @since MU
       
   290 		 *
       
   291 		 * @param string $context A string describing the steps of the sign-up process. The value can be
       
   292 		 *                        'create-another-site', 'validate-user', or 'validate-site'.
       
   293 		 */
       
   294 		do_action( 'signup_hidden_fields', 'create-another-site' );
       
   295 		?>
       
   296 		<?php show_blog_form($blogname, $blog_title, $errors); ?>
       
   297 		<p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ) ?>" /></p>
       
   298 	</form>
       
   299 	<?php
       
   300 }
       
   301 
       
   302 /**
       
   303  * Validate a new blog signup
       
   304  *
       
   305  * @since MU
       
   306  *
       
   307  * @uses wp_get_current_user() to retrieve the current user
       
   308  * @uses wpmu_create_blog() to add a new site
       
   309  * @uses confirm_another_blog_signup() to confirm the user's new site signup
       
   310  * @return bool True if blog signup was validated, false if error
       
   311  */
       
   312 function validate_another_blog_signup() {
       
   313 	global $wpdb, $blogname, $blog_title, $errors, $domain, $path;
       
   314 	$current_user = wp_get_current_user();
       
   315 	if ( !is_user_logged_in() )
       
   316 		die();
       
   317 
       
   318 	$result = validate_blog_form();
       
   319 	extract($result);
       
   320 
       
   321 	if ( $errors->get_error_code() ) {
       
   322 		signup_another_blog($blogname, $blog_title, $errors);
       
   323 		return false;
       
   324 	}
       
   325 
       
   326 	$public = (int) $_POST['blog_public'];
       
   327 
       
   328 	$blog_meta_defaults = array(
       
   329 		'lang_id' => 1,
       
   330 		'public'  => $public
       
   331 	);
       
   332 
       
   333 	/**
       
   334 	 * Filter the new site meta variables.
       
   335 	 *
       
   336 	 * @since MU
       
   337 	 * @deprecated 3.0.0 Use the 'add_signup_meta' filter instead.
       
   338 	 *
       
   339 	 * @param array $blog_meta_defaults An array of default blog meta variables.
       
   340 	 */
       
   341 	$meta = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults );
       
   342 	/**
       
   343 	 * Filter the new default site meta variables.
       
   344 	 *
       
   345 	 * @since 3.0.0
       
   346 	 *
       
   347 	 * @param array $meta {
       
   348 	 *     An array of default site meta variables.
       
   349 	 *
       
   350 	 *     @type int $lang_id     The language ID.
       
   351 	 *     @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
       
   352 	 * }
       
   353 	 */
       
   354 	$meta = apply_filters( 'add_signup_meta', $meta );
       
   355 
       
   356 	wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
       
   357 	confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
       
   358 	return true;
       
   359 }
       
   360 
       
   361 /**
       
   362  * Confirm a new site signup
       
   363  *
       
   364  * @since MU
       
   365  *
       
   366  * @param string $domain The domain URL
       
   367  * @param string $path The site root path
       
   368  * @param string $user_name The username
       
   369  * @param string $user_email The user's email address
       
   370  * @param array $meta Any additional meta from the 'add_signup_meta' filter in validate_blog_signup()
       
   371  */
       
   372 function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array() ) {
       
   373 	?>
       
   374 	<h2><?php printf( __( 'The site %s is yours.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
       
   375 	<p>
       
   376 		<?php printf( __( '<a href="http://%1$s">http://%2$s</a> is your new site. <a href="%3$s">Log in</a> as &#8220;%4$s&#8221; using your existing password.' ), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name ) ?>
       
   377 	</p>
       
   378 	<?php
       
   379 	/**
       
   380 	 * Fires when the site or user sign-up process is complete.
       
   381 	 *
       
   382 	 * @since 3.0.0
       
   383 	 */
       
   384 	do_action( 'signup_finished' );
       
   385 }
       
   386 
       
   387 /**
       
   388  * Setup the new user signup process
       
   389  *
       
   390  * @since MU
       
   391  *
       
   392  * @uses apply_filters() filter $filtered_results
       
   393  * @uses show_user_form() to display the user registration form
       
   394  * @param string $user_name The username
       
   395  * @param string $user_email The user's email
       
   396  * @param array $errors
       
   397  */
       
   398 function signup_user($user_name = '', $user_email = '', $errors = '') {
       
   399 	global $current_site, $active_signup;
       
   400 
       
   401 	if ( !is_wp_error($errors) )
       
   402 		$errors = new WP_Error();
       
   403 
       
   404 	$signup_for = isset( $_POST[ 'signup_for' ] ) ? esc_html( $_POST[ 'signup_for' ] ) : 'blog';
       
   405 
       
   406 	$signup_user_defaults = array(
       
   407 		'user_name'  => $user_name,
       
   408 		'user_email' => $user_email,
       
   409 		'errors'     => $errors,
       
   410 	);
       
   411 
       
   412 	/**
       
   413 	 * Filter the default user variables used on the user sign-up form.
       
   414 	 *
       
   415 	 * @since 3.0.0
       
   416 	 *
       
   417 	 * @param array $signup_user_defaults {
       
   418 	 *     An array of default user variables.
       
   419 	 *
       
   420 	 *     @type string $user_name  The user username.
       
   421 	 *     @type string $user_email The user email address.
       
   422 	 *     @type array  $errors     An array of possible errors relevant to the sign-up user.
       
   423 	 * }
       
   424 	 */
       
   425 	$filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
       
   426 	$user_name = $filtered_results['user_name'];
       
   427 	$user_email = $filtered_results['user_email'];
       
   428 	$errors = $filtered_results['errors'];
       
   429 
       
   430 	?>
       
   431 
       
   432 	<h2><?php printf( __( 'Get your own %s account in seconds' ), $current_site->site_name ) ?></h2>
       
   433 	<form id="setupform" method="post" action="wp-signup.php">
       
   434 		<input type="hidden" name="stage" value="validate-user-signup" />
       
   435 		<?php
       
   436 		/** This action is documented in wp-signup.php */
       
   437 		do_action( 'signup_hidden_fields', 'validate-user' );
       
   438 		?>
       
   439 		<?php show_user_form($user_name, $user_email, $errors); ?>
       
   440 
       
   441 		<p>
       
   442 		<?php if ( $active_signup == 'blog' ) { ?>
       
   443 			<input id="signupblog" type="hidden" name="signup_for" value="blog" />
       
   444 		<?php } elseif ( $active_signup == 'user' ) { ?>
       
   445 			<input id="signupblog" type="hidden" name="signup_for" value="user" />
       
   446 		<?php } else { ?>
       
   447 			<input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
       
   448 			<label class="checkbox" for="signupblog"><?php _e('Gimme a site!') ?></label>
       
   449 			<br />
       
   450 			<input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
       
   451 			<label class="checkbox" for="signupuser"><?php _e('Just a username, please.') ?></label>
       
   452 		<?php } ?>
       
   453 		</p>
       
   454 
       
   455 		<p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Next') ?>" /></p>
       
   456 	</form>
       
   457 	<?php
       
   458 }
       
   459 
       
   460 /**
       
   461  * Validate the new user signup
       
   462  *
       
   463  * @since MU
       
   464  *
       
   465  * @uses validate_user_form() to retrieve an array of the user data
       
   466  * @uses wpmu_signup_user() to signup the new user
       
   467  * @uses confirm_user_signup() to confirm the new user signup
       
   468  * @return bool True if new user signup was validated, false if error
       
   469  */
       
   470 function validate_user_signup() {
       
   471 	$result = validate_user_form();
       
   472 	extract($result);
       
   473 
       
   474 	if ( $errors->get_error_code() ) {
       
   475 		signup_user($user_name, $user_email, $errors);
       
   476 		return false;
       
   477 	}
       
   478 
       
   479 	if ( 'blog' == $_POST['signup_for'] ) {
       
   480 		signup_blog($user_name, $user_email);
       
   481 		return false;
       
   482 	}
       
   483 
       
   484 	/** This filter is documented in wp-signup.php */
       
   485 	wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
       
   486 
       
   487 	confirm_user_signup($user_name, $user_email);
       
   488 	return true;
       
   489 }
       
   490 
       
   491 /**
       
   492  * New user signup confirmation
       
   493  *
       
   494  * @since MU
       
   495  *
       
   496  * @param string $user_name The username
       
   497  * @param string $user_email The user's email address
       
   498  */
       
   499 function confirm_user_signup($user_name, $user_email) {
       
   500 	?>
       
   501 	<h2><?php printf( __( '%s is your new username' ), $user_name) ?></h2>
       
   502 	<p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ) ?></p>
       
   503 	<p><?php printf( __( 'Check your inbox at <strong>%s</strong> and click the link given.' ), $user_email ); ?></p>
       
   504 	<p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
       
   505 	<?php
       
   506 	/** This action is documented in wp-signup.php */
       
   507 	do_action( 'signup_finished' );
       
   508 }
       
   509 
       
   510 /**
       
   511  * Setup the new site signup
       
   512  *
       
   513  * @since MU
       
   514  *
       
   515  * @uses apply_filters() to filter $filtered_results
       
   516  * @uses show_blog_form() to display the blog signup form
       
   517  * @param string $user_name The username
       
   518  * @param string $user_email The user's email address
       
   519  * @param string $blogname The site name
       
   520  * @param string $blog_title The site title
       
   521  * @param array $errors
       
   522  */
       
   523 function signup_blog($user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '') {
       
   524 	if ( !is_wp_error($errors) )
       
   525 		$errors = new WP_Error();
       
   526 
       
   527 	$signup_blog_defaults = array(
       
   528 		'user_name'  => $user_name,
       
   529 		'user_email' => $user_email,
       
   530 		'blogname'   => $blogname,
       
   531 		'blog_title' => $blog_title,
       
   532 		'errors'     => $errors
       
   533 	);
       
   534 
       
   535 	/**
       
   536 	 * Filter the default site creation variables for the site sign-up form.
       
   537 	 *
       
   538 	 * @since 3.0.0
       
   539 	 *
       
   540 	 * @param array $signup_blog_defaults {
       
   541 	 *     An array of default site creation variables.
       
   542 	 *
       
   543 	 *     @type string $user_name  The user username.
       
   544 	 *     @type string $user_email The user email address.
       
   545 	 *     @type string $blogname   The blogname.
       
   546 	 *     @type string $blog_title The title of the site.
       
   547 	 *     @type array  $errors     An array of possible errors relevant to new site creation variables.
       
   548 	 * }
       
   549 	 */
       
   550 	$filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults );
       
   551 
       
   552 	$user_name = $filtered_results['user_name'];
       
   553 	$user_email = $filtered_results['user_email'];
       
   554 	$blogname = $filtered_results['blogname'];
       
   555 	$blog_title = $filtered_results['blog_title'];
       
   556 	$errors = $filtered_results['errors'];
       
   557 
       
   558 	if ( empty($blogname) )
       
   559 		$blogname = $user_name;
       
   560 	?>
       
   561 	<form id="setupform" method="post" action="wp-signup.php">
       
   562 		<input type="hidden" name="stage" value="validate-blog-signup" />
       
   563 		<input type="hidden" name="user_name" value="<?php echo esc_attr($user_name) ?>" />
       
   564 		<input type="hidden" name="user_email" value="<?php echo esc_attr($user_email) ?>" />
       
   565 		<?php
       
   566 		/** This action is documented in wp-signup.php */
       
   567 		do_action( 'signup_hidden_fields', 'validate-site' );
       
   568 		?>
       
   569 		<?php show_blog_form($blogname, $blog_title, $errors); ?>
       
   570 		<p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Signup') ?>" /></p>
       
   571 	</form>
       
   572 	<?php
       
   573 }
       
   574 
       
   575 /**
       
   576  * Validate new site signup
       
   577  *
       
   578  * @since MU
       
   579  *
       
   580  * @uses wpmu_validate_user_signup() to retrieve an array of the new user data and errors
       
   581  * @uses wpmu_validate_blog_signup() to retrieve an array of the new site data and errors
       
   582  * @uses apply_filters() to make signup $meta filterable
       
   583  * @uses signup_user() to signup a new user
       
   584  * @uses signup_blog() to signup a the new user to a new site
       
   585  * @return bool True if the site signup was validated, false if error
       
   586  */
       
   587 function validate_blog_signup() {
       
   588 	// Re-validate user info.
       
   589 	$result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
       
   590 	extract($result);
       
   591 
       
   592 	if ( $errors->get_error_code() ) {
       
   593 		signup_user($user_name, $user_email, $errors);
       
   594 		return false;
       
   595 	}
       
   596 
       
   597 	$result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']);
       
   598 	extract($result);
       
   599 
       
   600 	if ( $errors->get_error_code() ) {
       
   601 		signup_blog($user_name, $user_email, $blogname, $blog_title, $errors);
       
   602 		return false;
       
   603 	}
       
   604 
       
   605 	$public = (int) $_POST['blog_public'];
       
   606 	$meta = array ('lang_id' => 1, 'public' => $public);
       
   607 
       
   608 	/** This filter is documented in wp-signup.php */
       
   609 	$meta = apply_filters( 'add_signup_meta', $meta );
       
   610 
       
   611 	wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
       
   612 	confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
       
   613 	return true;
       
   614 }
       
   615 
       
   616 /**
       
   617  * New site signup confirmation
       
   618  *
       
   619  * @since MU
       
   620  *
       
   621  * @param string $domain The domain URL
       
   622  * @param string $path The site root path
       
   623  * @param string $blog_title The new site title
       
   624  * @param string $user_name The user's username
       
   625  * @param string $user_email The user's email address
       
   626  * @param array $meta Any additional meta from the 'add_signup_meta' filter in validate_blog_signup()
       
   627  */
       
   628 function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
       
   629 	?>
       
   630 	<h2><?php printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
       
   631 
       
   632 	<p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ) ?></p>
       
   633 	<p><?php printf( __( 'Check your inbox at <strong>%s</strong> and click the link given.' ),  $user_email) ?></p>
       
   634 	<p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
       
   635 	<h2><?php _e( 'Still waiting for your email?' ); ?></h2>
       
   636 	<p>
       
   637 		<?php _e( 'If you haven&#8217;t received your email yet, there are a number of things you can do:' ) ?>
       
   638 		<ul id="noemail-tips">
       
   639 			<li><p><strong><?php _e( 'Wait a little longer. Sometimes delivery of email can be delayed by processes outside of our control.' ) ?></strong></p></li>
       
   640 			<li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ) ?></p></li>
       
   641 			<li><?php printf( __( 'Have you entered your email correctly? You have entered %s, if it&#8217;s incorrect, you will not receive your email.' ), $user_email ) ?></li>
       
   642 		</ul>
       
   643 	</p>
       
   644 	<?php
       
   645 	/** This action is documented in wp-signup.php */
       
   646 	do_action( 'signup_finished' );
       
   647 }
       
   648 
       
   649 // Main
       
   650 $active_signup = get_site_option( 'registration', 'none' );
       
   651 /**
       
   652  * Filter the type of site sign-up.
       
   653  *
       
   654  * @since 3.0.0
       
   655  *
       
   656  * @param string $active_signup String that returns registration type. The value can be
       
   657  *                              'all', 'none', 'blog', or 'user'.
       
   658  */
       
   659 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
       
   660 
       
   661 // Make the signup type translatable.
       
   662 $i18n_signup['all'] = _x('all', 'Multisite active signup type');
       
   663 $i18n_signup['none'] = _x('none', 'Multisite active signup type');
       
   664 $i18n_signup['blog'] = _x('blog', 'Multisite active signup type');
       
   665 $i18n_signup['user'] = _x('user', 'Multisite active signup type');
       
   666 
       
   667 if ( is_super_admin() )
       
   668 	echo '<div class="mu_alert">' . sprintf( __( 'Greetings Site Administrator! You are currently allowing &#8220;%s&#8221; registrations. To change or disable registration go to your <a href="%s">Options page</a>.' ), $i18n_signup[$active_signup], esc_url( network_admin_url( 'settings.php' ) ) ) . '</div>';
       
   669 
       
   670 $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
       
   671 
       
   672 $current_user = wp_get_current_user();
       
   673 if ( $active_signup == 'none' ) {
       
   674 	_e( 'Registration has been disabled.' );
       
   675 } elseif ( $active_signup == 'blog' && !is_user_logged_in() ) {
       
   676 	$login_url = site_url( 'wp-login.php?redirect_to=' . urlencode( network_site_url( 'wp-signup.php' ) ) );
       
   677 	echo sprintf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
       
   678 } else {
       
   679 	$stage = isset( $_POST['stage'] ) ?  $_POST['stage'] : 'default';
       
   680 	switch ( $stage ) {
       
   681 		case 'validate-user-signup' :
       
   682 			if ( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
       
   683 				validate_user_signup();
       
   684 			else
       
   685 				_e( 'User registration has been disabled.' );
       
   686 		break;
       
   687 		case 'validate-blog-signup':
       
   688 			if ( $active_signup == 'all' || $active_signup == 'blog' )
       
   689 				validate_blog_signup();
       
   690 			else
       
   691 				_e( 'Site registration has been disabled.' );
       
   692 			break;
       
   693 		case 'gimmeanotherblog':
       
   694 			validate_another_blog_signup();
       
   695 			break;
       
   696 		case 'default':
       
   697 		default :
       
   698 			$user_email = isset( $_POST[ 'user_email' ] ) ? $_POST[ 'user_email' ] : '';
       
   699 			/**
       
   700 			 * Fires when the site sign-up form is sent.
       
   701 			 *
       
   702 			 * @since 3.0.0
       
   703 			 */
       
   704 			do_action( 'preprocess_signup_form' );
       
   705 			if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) )
       
   706 				signup_another_blog($newblogname);
       
   707 			elseif ( is_user_logged_in() == false && ( $active_signup == 'all' || $active_signup == 'user' ) )
       
   708 				signup_user( $newblogname, $user_email );
       
   709 			elseif ( is_user_logged_in() == false && ( $active_signup == 'blog' ) )
       
   710 				_e( 'Sorry, new registrations are not allowed at this time.' );
       
   711 			else
       
   712 				_e( 'You are logged in already. No need to register again!' );
       
   713 
       
   714 			if ( $newblogname ) {
       
   715 				$newblog = get_blogaddress_by_name( $newblogname );
       
   716 
       
   717 				if ( $active_signup == 'blog' || $active_signup == 'all' )
       
   718 					printf( '<p><em>' . __( 'The site you were looking for, <strong>%s</strong>, does not exist, but you can create it now!' ) . '</em></p>', $newblog );
       
   719 				else
       
   720 					printf( '<p><em>' . __( 'The site you were looking for, <strong>%s</strong>, does not exist.' ) . '</em></p>', $newblog );
       
   721 			}
       
   722 			break;
       
   723 	}
       
   724 }
       
   725 ?>
       
   726 </div>
       
   727 </div>
       
   728 <?php
       
   729 /**
       
   730  * Fires after the sign-up forms, before wp_footer.
       
   731  *
       
   732  * @since 3.0.0
       
   733  */
       
   734 do_action( 'after_signup_form' ); ?>
       
   735 
       
   736 <?php get_footer(); ?>