3 /** Sets up the WordPress Environment. */
4 require( dirname(__FILE__) . '/wp-load.php' );
6 add_action( 'wp_head', 'wp_no_robots' );
8 require( './wp-blog-header.php' );
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() );
16 * Prints signup_header via wp_head
20 function do_signup_header() {
21 do_action( 'signup_header' );
23 add_action( 'wp_head', 'do_signup_header' );
25 if ( !is_multisite() ) {
26 wp_redirect( site_url('wp-login.php?action=register') );
30 if ( !is_main_site() ) {
31 wp_redirect( network_site_url( 'wp-signup.php' ) );
36 $wp_query->is_404 = false;
39 * Prints styles for front-end Multisite signup pages
43 function wpmu_signup_stylesheet() {
45 <style type="text/css">
46 .mu_register { width: 90%; margin:0 auto; }
47 .mu_register form { margin-top: 2em; }
48 .mu_register .error { font-weight:700; padding:10px; color:#333333; background:#FFEBE8; border:1px solid #CC0000; }
49 .mu_register input[type="submit"],
50 .mu_register #blog_title,
51 .mu_register #user_email,
52 .mu_register #blogname,
53 .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }
54 .mu_register .prefix_address,
55 .mu_register .suffix_address {font-size: 18px;display:inline; }
56 .mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
57 .mu_register label.checkbox { display:inline; }
58 .mu_register .mu_alert { font-weight:700; padding:10px; color:#333333; background:#ffffe0; border:1px solid #e6db55; }
63 add_action( 'wp_head', 'wpmu_signup_stylesheet' );
66 do_action( 'before_signup_form' );
68 <div id="content" class="widecolumn">
69 <div class="mu_register">
72 * Generates and displays the Signup and Create Site forms
76 * @param string $blogname The new site name
77 * @param string $blog_title The new site title
78 * @param array $errors
80 function show_blog_form($blogname = '', $blog_title = '', $errors = '') {
83 if ( !is_subdomain_install() )
84 echo '<label for="blogname">' . __('Site Name:') . '</label>';
86 echo '<label for="blogname">' . __('Site Domain:') . '</label>';
88 if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
89 <p class="error"><?php echo $errmsg ?></p>
92 if ( !is_subdomain_install() )
93 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 />';
95 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 />';
97 if ( !is_user_logged_in() ) {
98 if ( !is_subdomain_install() )
99 $site = $current_site->domain . $current_site->path . __( 'sitename' );
101 $site = __( 'domain' ) . '.' . $site_domain . $current_site->path;
102 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>';
107 <label for="blog_title"><?php _e('Site Title:') ?></label>
108 <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
109 <p class="error"><?php echo $errmsg ?></p>
111 echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />';
115 <p class="privacy-intro">
116 <label for="blog_public_on"><?php _e('Privacy:') ?></label>
117 <?php _e( 'Allow search engines to index this site.' ); ?>
118 <br style="clear:both" />
119 <label class="checkbox" for="blog_public_on">
120 <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 } ?> />
121 <strong><?php _e( 'Yes' ); ?></strong>
123 <label class="checkbox" for="blog_public_off">
124 <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 } ?> />
125 <strong><?php _e( 'No' ); ?></strong>
131 do_action('signup_blogform', $errors);
135 * Validate the new site signup
139 * @uses wp_get_current_user() to retrieve the current user
140 * @uses wpmu_validate_blog_signup() to validate new site signup for the current user
141 * @return array Contains the new site data and error messages.
143 function validate_blog_form() {
145 if ( is_user_logged_in() )
146 $user = wp_get_current_user();
148 return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
152 * Display user registration form
156 * @param string $user_name The entered username
157 * @param string $user_email The entered email address
158 * @param array $errors
160 function show_user_form($user_name = '', $user_email = '', $errors = '') {
162 echo '<label for="user_name">' . __('Username:') . '</label>';
163 if ( $errmsg = $errors->get_error_message('user_name') ) {
164 echo '<p class="error">'.$errmsg.'</p>';
166 echo '<input name="user_name" type="text" id="user_name" value="'. esc_attr($user_name) .'" maxlength="60" /><br />';
167 _e( '(Must be at least 4 characters, letters and numbers only.)' );
170 <label for="user_email"><?php _e( 'Email Address:' ) ?></label>
171 <?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
172 <p class="error"><?php echo $errmsg ?></p>
174 <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.)') ?>
176 if ( $errmsg = $errors->get_error_message('generic') ) {
177 echo '<p class="error">' . $errmsg . '</p>';
179 do_action( 'signup_extra_fields', $errors );
183 * Validate user signup name and email
187 * @uses wpmu_validate_user_signup() to retrieve an array of user data
188 * @return array Contains username, email, and error messages.
190 function validate_user_form() {
191 return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
195 * Allow returning users to sign up for another site
199 * @uses wp_get_current_user() to get the current user
200 * @param string $blogname The new site name
201 * @param string $blog_title The new blog title
202 * @param array $errors
204 function signup_another_blog($blogname = '', $blog_title = '', $errors = '') {
205 global $current_site;
206 $current_user = wp_get_current_user();
208 if ( ! is_wp_error($errors) ) {
209 $errors = new WP_Error();
212 // allow definition of default variables
213 $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
214 $blogname = $filtered_results['blogname'];
215 $blog_title = $filtered_results['blog_title'];
216 $errors = $filtered_results['errors'];
218 echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), $current_site->site_name ) . '</h2>';
220 if ( $errors->get_error_code() ) {
221 echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
224 <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’s content, but write responsibly!' ), $current_user->display_name ) ?></p>
227 $blogs = get_blogs_of_user($current_user->ID);
228 if ( !empty($blogs) ) { ?>
230 <p><?php _e( 'Sites you are already a member of:' ) ?></p>
232 <?php foreach ( $blogs as $blog ) {
233 $home_url = get_home_url( $blog->userblog_id );
234 echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
239 <p><?php _e( 'If you’re not going to use a great site domain, leave it for a new user. Now have at it!' ) ?></p>
240 <form id="setupform" method="post" action="wp-signup.php">
241 <input type="hidden" name="stage" value="gimmeanotherblog" />
242 <?php do_action( 'signup_hidden_fields' ); ?>
243 <?php show_blog_form($blogname, $blog_title, $errors); ?>
244 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ) ?>" /></p>
250 * Validate a new blog signup
254 * @uses wp_get_current_user() to retrieve the current user
255 * @uses wpmu_create_blog() to add a new site
256 * @uses confirm_another_blog_signup() to confirm the user's new site signup
257 * @return bool True if blog signup was validated, false if error
259 function validate_another_blog_signup() {
260 global $wpdb, $blogname, $blog_title, $errors, $domain, $path;
261 $current_user = wp_get_current_user();
262 if ( !is_user_logged_in() )
265 $result = validate_blog_form();
268 if ( $errors->get_error_code() ) {
269 signup_another_blog($blogname, $blog_title, $errors);
273 $public = (int) $_POST['blog_public'];
274 $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // deprecated
275 $meta = apply_filters( 'add_signup_meta', $meta );
277 wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
278 confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
283 * Confirm a new site signup
287 * @param string $domain The domain URL
288 * @param string $path The site root path
289 * @param string $user_name The username
290 * @param string $user_email The user's email address
291 * @param array $meta Any additional meta from the 'add_signup_meta' filter in validate_blog_signup()
293 function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array() ) {
295 <h2><?php printf( __( 'The site %s is yours.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
297 <?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.' ), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name ) ?>
300 do_action( 'signup_finished' );
304 * Setup the new user signup process
308 * @uses apply_filters() filter $filtered_results
309 * @uses show_user_form() to display the user registration form
310 * @param string $user_name The username
311 * @param string $user_email The user's email
312 * @param array $errors
314 function signup_user($user_name = '', $user_email = '', $errors = '') {
315 global $current_site, $active_signup;
317 if ( !is_wp_error($errors) )
318 $errors = new WP_Error();
320 $signup_for = isset( $_POST[ 'signup_for' ] ) ? esc_html( $_POST[ 'signup_for' ] ) : 'blog';
322 // allow definition of default variables
323 $filtered_results = apply_filters('signup_user_init', array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors ));
324 $user_name = $filtered_results['user_name'];
325 $user_email = $filtered_results['user_email'];
326 $errors = $filtered_results['errors'];
330 <h2><?php printf( __( 'Get your own %s account in seconds' ), $current_site->site_name ) ?></h2>
331 <form id="setupform" method="post" action="wp-signup.php">
332 <input type="hidden" name="stage" value="validate-user-signup" />
333 <?php do_action( 'signup_hidden_fields' ); ?>
334 <?php show_user_form($user_name, $user_email, $errors); ?>
337 <?php if ( $active_signup == 'blog' ) { ?>
338 <input id="signupblog" type="hidden" name="signup_for" value="blog" />
339 <?php } elseif ( $active_signup == 'user' ) { ?>
340 <input id="signupblog" type="hidden" name="signup_for" value="user" />
342 <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
343 <label class="checkbox" for="signupblog"><?php _e('Gimme a site!') ?></label>
345 <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
346 <label class="checkbox" for="signupuser"><?php _e('Just a username, please.') ?></label>
350 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Next') ?>" /></p>
356 * Validate the new user signup
360 * @uses validate_user_form() to retrieve an array of the user data
361 * @uses wpmu_signup_user() to signup the new user
362 * @uses confirm_user_signup() to confirm the new user signup
363 * @return bool True if new user signup was validated, false if error
365 function validate_user_signup() {
366 $result = validate_user_form();
369 if ( $errors->get_error_code() ) {
370 signup_user($user_name, $user_email, $errors);
374 if ( 'blog' == $_POST['signup_for'] ) {
375 signup_blog($user_name, $user_email);
379 wpmu_signup_user($user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
381 confirm_user_signup($user_name, $user_email);
386 * New user signup confirmation
390 * @param string $user_name The username
391 * @param string $user_email The user's email address
393 function confirm_user_signup($user_name, $user_email) {
395 <h2><?php printf( __( '%s is your new username' ), $user_name) ?></h2>
396 <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ) ?></p>
397 <p><?php printf( __( 'Check your inbox at <strong>%s</strong> and click the link given.' ), $user_email ); ?></p>
398 <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
400 do_action( 'signup_finished' );
404 * Setup the new site signup
408 * @uses apply_filters() to filter $filtered_results
409 * @uses show_blog_form() to display the blog signup form
410 * @param string $user_name The username
411 * @param string $user_email The user's email address
412 * @param string $blogname The site name
413 * @param string $blog_title The site title
414 * @param array $errors
416 function signup_blog($user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '') {
417 if ( !is_wp_error($errors) )
418 $errors = new WP_Error();
420 // allow definition of default variables
421 $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
422 $user_name = $filtered_results['user_name'];
423 $user_email = $filtered_results['user_email'];
424 $blogname = $filtered_results['blogname'];
425 $blog_title = $filtered_results['blog_title'];
426 $errors = $filtered_results['errors'];
428 if ( empty($blogname) )
429 $blogname = $user_name;
431 <form id="setupform" method="post" action="wp-signup.php">
432 <input type="hidden" name="stage" value="validate-blog-signup" />
433 <input type="hidden" name="user_name" value="<?php echo esc_attr($user_name) ?>" />
434 <input type="hidden" name="user_email" value="<?php echo esc_attr($user_email) ?>" />
435 <?php do_action( 'signup_hidden_fields' ); ?>
436 <?php show_blog_form($blogname, $blog_title, $errors); ?>
437 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Signup') ?>" /></p>
443 * Validate new site signup
447 * @uses wpmu_validate_user_signup() to retrieve an array of the new user data and errors
448 * @uses wpmu_validate_blog_signup() to retrieve an array of the new site data and errors
449 * @uses apply_filters() to make signup $meta filterable
450 * @uses signup_user() to signup a new user
451 * @uses signup_blog() to signup a the new user to a new site
452 * @return bool True if the site signup was validated, false if error
454 function validate_blog_signup() {
455 // Re-validate user info.
456 $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
459 if ( $errors->get_error_code() ) {
460 signup_user($user_name, $user_email, $errors);
464 $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']);
467 if ( $errors->get_error_code() ) {
468 signup_blog($user_name, $user_email, $blogname, $blog_title, $errors);
472 $public = (int) $_POST['blog_public'];
473 $meta = array ('lang_id' => 1, 'public' => $public);
474 $meta = apply_filters( 'add_signup_meta', $meta );
476 wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
477 confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
482 * New site signup confirmation
486 * @param string $domain The domain URL
487 * @param string $path The site root path
488 * @param string $blog_title The new site title
489 * @param string $user_name The user's username
490 * @param string $user_email The user's email address
491 * @param array $meta Any additional meta from the 'add_signup_meta' filter in validate_blog_signup()
493 function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
495 <h2><?php printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
497 <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ) ?></p>
498 <p><?php printf( __( 'Check your inbox at <strong>%s</strong> and click the link given.' ), $user_email) ?></p>
499 <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
500 <h2><?php _e( 'Still waiting for your email?' ); ?></h2>
502 <?php _e( 'If you haven’t received your email yet, there are a number of things you can do:' ) ?>
503 <ul id="noemail-tips">
504 <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>
505 <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ) ?></p></li>
506 <li><?php printf( __( 'Have you entered your email correctly? You have entered %s, if it’s incorrect, you will not receive your email.' ), $user_email ) ?></li>
510 do_action( 'signup_finished' );
514 $active_signup = get_site_option( 'registration' );
515 if ( !$active_signup )
516 $active_signup = 'all';
518 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
520 // Make the signup type translatable.
521 $i18n_signup['all'] = _x('all', 'Multisite active signup type');
522 $i18n_signup['none'] = _x('none', 'Multisite active signup type');
523 $i18n_signup['blog'] = _x('blog', 'Multisite active signup type');
524 $i18n_signup['user'] = _x('user', 'Multisite active signup type');
526 if ( is_super_admin() )
527 echo '<div class="mu_alert">' . sprintf( __( 'Greetings Site Administrator! You are currently allowing “%s” 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>';
529 $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
531 $current_user = wp_get_current_user();
532 if ( $active_signup == 'none' ) {
533 _e( 'Registration has been disabled.' );
534 } elseif ( $active_signup == 'blog' && !is_user_logged_in() ) {
535 $login_url = site_url( 'wp-login.php?redirect_to=' . urlencode( network_site_url( 'wp-signup.php' ) ) );
536 echo sprintf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
538 $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default';
540 case 'validate-user-signup' :
541 if ( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
542 validate_user_signup();
544 _e( 'User registration has been disabled.' );
546 case 'validate-blog-signup':
547 if ( $active_signup == 'all' || $active_signup == 'blog' )
548 validate_blog_signup();
550 _e( 'Site registration has been disabled.' );
552 case 'gimmeanotherblog':
553 validate_another_blog_signup();
557 $user_email = isset( $_POST[ 'user_email' ] ) ? $_POST[ 'user_email' ] : '';
558 do_action( 'preprocess_signup_form' ); // populate the form from invites, elsewhere?
559 if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) )
560 signup_another_blog($newblogname);
561 elseif ( is_user_logged_in() == false && ( $active_signup == 'all' || $active_signup == 'user' ) )
562 signup_user( $newblogname, $user_email );
563 elseif ( is_user_logged_in() == false && ( $active_signup == 'blog' ) )
564 _e( 'Sorry, new registrations are not allowed at this time.' );
566 _e( 'You are logged in already. No need to register again!' );
568 if ( $newblogname ) {
569 $newblog = get_blogaddress_by_name( $newblogname );
571 if ( $active_signup == 'blog' || $active_signup == 'all' )
572 printf( '<p><em>' . __( 'The site you were looking for, <strong>%s</strong>, does not exist, but you can create it now!' ) . '</em></p>', $newblog );
574 printf( '<p><em>' . __( 'The site you were looking for, <strong>%s</strong>, does not exist.' ) . '</em></p>', $newblog );
582 <?php do_action( 'after_signup_form' ); ?>
584 <?php get_footer(); ?>