]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-signup.php
WordPress 4.5.2-scripts
[autoinstalls/wordpress.git] / wp-signup.php
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' ) ) ) {
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( wp_registration_url() );
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  * Fires before the Site Signup page is loaded.
45  *
46  * @since 4.4.0
47  */
48 do_action( 'before_signup_header' );
49
50 /**
51  * Prints styles for front-end Multisite signup pages
52  *
53  * @since MU
54  */
55 function wpmu_signup_stylesheet() {
56         ?>
57         <style type="text/css">
58                 .mu_register { width: 90%; margin:0 auto; }
59                 .mu_register form { margin-top: 2em; }
60                 .mu_register .error { font-weight:700; padding:10px; color:#333333; background:#FFEBE8; border:1px solid #CC0000; }
61                 .mu_register input[type="submit"],
62                         .mu_register #blog_title,
63                         .mu_register #user_email,
64                         .mu_register #blogname,
65                         .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }
66                 .mu_register #site-language { display: block; }
67                 .mu_register .prefix_address,
68                         .mu_register .suffix_address {font-size: 18px;display:inline; }
69                 .mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
70                 .mu_register label.checkbox { display:inline; }
71                 .mu_register .mu_alert { font-weight:700; padding:10px; color:#333333; background:#ffffe0; border:1px solid #e6db55; }
72         </style>
73         <?php
74 }
75
76 add_action( 'wp_head', 'wpmu_signup_stylesheet' );
77 get_header( 'wp-signup' );
78
79 /**
80  * Fires before the site sign-up form.
81  *
82  * @since 3.0.0
83  */
84 do_action( 'before_signup_form' );
85 ?>
86 <div id="signup-content" class="widecolumn">
87 <div class="mu_register wp-signup-container">
88 <?php
89 /**
90  * Generates and displays the Signup and Create Site forms
91  *
92  * @since MU
93  *
94  * @param string $blogname The new site name
95  * @param string $blog_title The new site title
96  * @param array $errors
97  */
98 function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
99         $current_site = get_current_site();
100         // Blog name
101         if ( !is_subdomain_install() )
102                 echo '<label for="blogname">' . __('Site Name:') . '</label>';
103         else
104                 echo '<label for="blogname">' . __('Site Domain:') . '</label>';
105
106         if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
107                 <p class="error"><?php echo $errmsg ?></p>
108         <?php }
109
110         if ( !is_subdomain_install() )
111                 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 />';
112         else
113                 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 />';
114
115         if ( !is_user_logged_in() ) {
116                 if ( !is_subdomain_install() )
117                         $site = $current_site->domain . $current_site->path . __( 'sitename' );
118                 else
119                         $site = __( 'domain' ) . '.' . $site_domain . $current_site->path;
120                 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>';
121         }
122
123         // Blog Title
124         ?>
125         <label for="blog_title"><?php _e('Site Title:') ?></label>
126         <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
127                 <p class="error"><?php echo $errmsg ?></p>
128         <?php }
129         echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />';
130         ?>
131
132         <?php
133         // Site Language.
134         $languages = signup_get_available_languages();
135
136         if ( ! empty( $languages ) ) :
137                 ?>
138                 <p>
139                         <label for="site-language"><?php _e( 'Site Language:' ); ?></label>
140                         <?php
141                         // Network default.
142                         $lang = get_site_option( 'WPLANG' );
143
144                         if ( isset( $_POST['WPLANG'] ) ) {
145                                 $lang = $_POST['WPLANG'];
146                         }
147
148                         // Use US English if the default isn't available.
149                         if ( ! in_array( $lang, $languages ) ) {
150                                 $lang = '';
151                         }
152
153                         wp_dropdown_languages( array(
154                                 'name'                        => 'WPLANG',
155                                 'id'                          => 'site-language',
156                                 'selected'                    => $lang,
157                                 'languages'                   => $languages,
158                                 'show_available_translations' => false,
159                         ) );
160                         ?>
161                 </p>
162         <?php endif; // Languages. ?>
163
164         <div id="privacy">
165         <p class="privacy-intro">
166             <label for="blog_public_on"><?php _e('Privacy:') ?></label>
167             <?php _e( 'Allow search engines to index this site.' ); ?>
168             <br style="clear:both" />
169             <label class="checkbox" for="blog_public_on">
170                 <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 } ?> />
171                 <strong><?php _e( 'Yes' ); ?></strong>
172             </label>
173             <label class="checkbox" for="blog_public_off">
174                 <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 } ?> />
175                 <strong><?php _e( 'No' ); ?></strong>
176             </label>
177         </p>
178         </div>
179
180         <?php
181         /**
182          * Fires after the site sign-up form.
183          *
184          * @since 3.0.0
185          *
186          * @param array $errors An array possibly containing 'blogname' or 'blog_title' errors.
187          */
188         do_action( 'signup_blogform', $errors );
189 }
190
191 /**
192  * Validate the new site signup
193  *
194  * @since MU
195  *
196  * @return array Contains the new site data and error messages.
197  */
198 function validate_blog_form() {
199         $user = '';
200         if ( is_user_logged_in() )
201                 $user = wp_get_current_user();
202
203         return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
204 }
205
206 /**
207  * Display user registration form
208  *
209  * @since MU
210  *
211  * @param string $user_name The entered username
212  * @param string $user_email The entered email address
213  * @param array $errors
214  */
215 function show_user_form($user_name = '', $user_email = '', $errors = '') {
216         // User name
217         echo '<label for="user_name">' . __('Username:') . '</label>';
218         if ( $errmsg = $errors->get_error_message('user_name') ) {
219                 echo '<p class="error">'.$errmsg.'</p>';
220         }
221         echo '<input name="user_name" type="text" id="user_name" value="'. esc_attr($user_name) .'" maxlength="60" /><br />';
222         _e( '(Must be at least 4 characters, letters and numbers only.)' );
223         ?>
224
225         <label for="user_email"><?php _e( 'Email&nbsp;Address:' ) ?></label>
226         <?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
227                 <p class="error"><?php echo $errmsg ?></p>
228         <?php } ?>
229         <input name="user_email" type="email" 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.)') ?>
230         <?php
231         if ( $errmsg = $errors->get_error_message('generic') ) {
232                 echo '<p class="error">' . $errmsg . '</p>';
233         }
234         /**
235          * Fires at the end of the user registration form on the site sign-up form.
236          *
237          * @since 3.0.0
238          *
239          * @param array $errors An array possibly containing 'user_name' or 'user_email' errors.
240          */
241         do_action( 'signup_extra_fields', $errors );
242 }
243
244 /**
245  * Validate user signup name and email
246  *
247  * @since MU
248  *
249  * @return array Contains username, email, and error messages.
250  */
251 function validate_user_form() {
252         return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
253 }
254
255 /**
256  * Allow returning users to sign up for another site
257  *
258  * @since MU
259  *
260  * @param string $blogname The new site name
261  * @param string $blog_title The new site title.
262  * @param array $errors
263  */
264 function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) {
265         $current_user = wp_get_current_user();
266
267         if ( ! is_wp_error($errors) ) {
268                 $errors = new WP_Error();
269         }
270
271         $signup_defaults = array(
272                 'blogname'   => $blogname,
273                 'blog_title' => $blog_title,
274                 'errors'     => $errors
275         );
276
277         /**
278          * Filter the default site sign-up variables.
279          *
280          * @since 3.0.0
281          *
282          * @param array $signup_defaults {
283          *     An array of default site sign-up variables.
284          *
285          *     @type string $blogname   The site blogname.
286          *     @type string $blog_title The site title.
287          *     @type array  $errors     An array possibly containing 'blogname' or 'blog_title' errors.
288          * }
289          */
290         $filtered_results = apply_filters( 'signup_another_blog_init', $signup_defaults );
291
292         $blogname = $filtered_results['blogname'];
293         $blog_title = $filtered_results['blog_title'];
294         $errors = $filtered_results['errors'];
295
296         echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), get_current_site()->site_name ) . '</h2>';
297
298         if ( $errors->get_error_code() ) {
299                 echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
300         }
301         ?>
302         <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>
303
304         <?php
305         $blogs = get_blogs_of_user($current_user->ID);
306         if ( !empty($blogs) ) { ?>
307
308                         <p><?php _e( 'Sites you are already a member of:' ) ?></p>
309                         <ul>
310                                 <?php foreach ( $blogs as $blog ) {
311                                         $home_url = get_home_url( $blog->userblog_id );
312                                         echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
313                                 } ?>
314                         </ul>
315         <?php } ?>
316
317         <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>
318         <form id="setupform" method="post" action="wp-signup.php">
319                 <input type="hidden" name="stage" value="gimmeanotherblog" />
320                 <?php
321                 /**
322                  * Hidden sign-up form fields output when creating another site or user.
323                  *
324                  * @since MU
325                  *
326                  * @param string $context A string describing the steps of the sign-up process. The value can be
327                  *                        'create-another-site', 'validate-user', or 'validate-site'.
328                  */
329                 do_action( 'signup_hidden_fields', 'create-another-site' );
330                 ?>
331                 <?php show_blog_form($blogname, $blog_title, $errors); ?>
332                 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ) ?>" /></p>
333         </form>
334         <?php
335 }
336
337 /**
338  * Validate a new site signup.
339  *
340  * @since MU
341  *
342  * @return null|bool True if site signup was validated, false if error.
343  *                   The function halts all execution if the user is not logged in.
344  */
345 function validate_another_blog_signup() {
346         global $wpdb, $blogname, $blog_title, $errors, $domain, $path;
347         $current_user = wp_get_current_user();
348         if ( ! is_user_logged_in() ) {
349                 die();
350         }
351
352         $result = validate_blog_form();
353
354         // Extracted values set/overwrite globals.
355         $domain = $result['domain'];
356         $path = $result['path'];
357         $blogname = $result['blogname'];
358         $blog_title = $result['blog_title'];
359         $errors = $result['errors'];
360
361         if ( $errors->get_error_code() ) {
362                 signup_another_blog($blogname, $blog_title, $errors);
363                 return false;
364         }
365
366         $public = (int) $_POST['blog_public'];
367
368         $blog_meta_defaults = array(
369                 'lang_id' => 1,
370                 'public'  => $public
371         );
372
373         // Handle the language setting for the new site.
374         if ( ! empty( $_POST['WPLANG'] ) ) {
375
376                 $languages = signup_get_available_languages();
377
378                 if ( in_array( $_POST['WPLANG'], $languages ) ) {
379                         $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
380
381                         if ( $language ) {
382                                 $blog_meta_defaults['WPLANG'] = $language;
383                         }
384                 }
385
386         }
387
388         /**
389          * Filter the new site meta variables.
390          *
391          * @since MU
392          * @deprecated 3.0.0 Use the 'add_signup_meta' filter instead.
393          *
394          * @param array $blog_meta_defaults An array of default blog meta variables.
395          */
396         $meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults );
397
398         /**
399          * Filter the new default site meta variables.
400          *
401          * @since 3.0.0
402          *
403          * @param array $meta {
404          *     An array of default site meta variables.
405          *
406          *     @type int $lang_id     The language ID.
407          *     @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
408          * }
409          */
410         $meta = apply_filters( 'add_signup_meta', $meta_defaults );
411
412         $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
413
414         if ( is_wp_error( $blog_id ) ) {
415                 return false;
416         }
417
418         confirm_another_blog_signup( $domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta, $blog_id );
419         return true;
420 }
421
422 /**
423  * Confirm a new site signup.
424  *
425  * @since MU
426  * @since 4.4.0 Added the `$blog_id` parameter.
427  *
428  * @param string $domain     The domain URL.
429  * @param string $path       The site root path.
430  * @param string $blog_title The site title.
431  * @param string $user_name  The username.
432  * @param string $user_email The user's email address.
433  * @param array  $meta       Any additional meta from the 'add_signup_meta' filter in validate_blog_signup().
434  * @param int    $blog_id    The site ID.
435  */
436 function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 ) {
437
438         if ( $blog_id ) {
439                 switch_to_blog( $blog_id );
440                 $home_url  = home_url( '/' );
441                 $login_url = wp_login_url();
442                 restore_current_blog();
443         } else {
444                 $home_url  = 'http://' . $domain . $path;
445                 $login_url = 'http://' . $domain . $path . 'wp-login.php';
446         }
447
448         $site = sprintf( '<a href="%1$s">%2$s</a>',
449                 esc_url( $home_url ),
450                 $blog_title
451         );
452
453         ?>
454         <h2><?php printf( __( 'The site %s is yours.' ), $site ); ?></h2>
455         <p>
456                 <?php printf(
457                         __( '<a href="%1$s">%2$s</a> is your new site. <a href="%3$s">Log in</a> as &#8220;%4$s&#8221; using your existing password.' ),
458                         esc_url( $home_url ),
459                         untrailingslashit( $domain . $path ),
460                         esc_url( $login_url ),
461                         $user_name
462                 ); ?>
463         </p>
464         <?php
465         /**
466          * Fires when the site or user sign-up process is complete.
467          *
468          * @since 3.0.0
469          */
470         do_action( 'signup_finished' );
471 }
472
473 /**
474  * Setup the new user signup process
475  *
476  * @since MU
477  *
478  * @param string $user_name The username
479  * @param string $user_email The user's email
480  * @param array $errors
481  */
482 function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
483         global $active_signup;
484
485         if ( !is_wp_error($errors) )
486                 $errors = new WP_Error();
487
488         $signup_for = isset( $_POST[ 'signup_for' ] ) ? esc_html( $_POST[ 'signup_for' ] ) : 'blog';
489
490         $signup_user_defaults = array(
491                 'user_name'  => $user_name,
492                 'user_email' => $user_email,
493                 'errors'     => $errors,
494         );
495
496         /**
497          * Filter the default user variables used on the user sign-up form.
498          *
499          * @since 3.0.0
500          *
501          * @param array $signup_user_defaults {
502          *     An array of default user variables.
503          *
504          *     @type string $user_name  The user username.
505          *     @type string $user_email The user email address.
506          *     @type array  $errors     An array of possible errors relevant to the sign-up user.
507          * }
508          */
509         $filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
510         $user_name = $filtered_results['user_name'];
511         $user_email = $filtered_results['user_email'];
512         $errors = $filtered_results['errors'];
513
514         ?>
515
516         <h2><?php printf( __( 'Get your own %s account in seconds' ), get_current_site()->site_name ) ?></h2>
517         <form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
518                 <input type="hidden" name="stage" value="validate-user-signup" />
519                 <?php
520                 /** This action is documented in wp-signup.php */
521                 do_action( 'signup_hidden_fields', 'validate-user' );
522                 ?>
523                 <?php show_user_form($user_name, $user_email, $errors); ?>
524
525                 <p>
526                 <?php if ( $active_signup == 'blog' ) { ?>
527                         <input id="signupblog" type="hidden" name="signup_for" value="blog" />
528                 <?php } elseif ( $active_signup == 'user' ) { ?>
529                         <input id="signupblog" type="hidden" name="signup_for" value="user" />
530                 <?php } else { ?>
531                         <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
532                         <label class="checkbox" for="signupblog"><?php _e('Gimme a site!') ?></label>
533                         <br />
534                         <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
535                         <label class="checkbox" for="signupuser"><?php _e('Just a username, please.') ?></label>
536                 <?php } ?>
537                 </p>
538
539                 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Next') ?>" /></p>
540         </form>
541         <?php
542 }
543
544 /**
545  * Validate the new user signup
546  *
547  * @since MU
548  *
549  * @return bool True if new user signup was validated, false if error
550  */
551 function validate_user_signup() {
552         $result = validate_user_form();
553         $user_name = $result['user_name'];
554         $user_email = $result['user_email'];
555         $errors = $result['errors'];
556
557         if ( $errors->get_error_code() ) {
558                 signup_user($user_name, $user_email, $errors);
559                 return false;
560         }
561
562         if ( 'blog' == $_POST['signup_for'] ) {
563                 signup_blog($user_name, $user_email);
564                 return false;
565         }
566
567         /** This filter is documented in wp-signup.php */
568         wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
569
570         confirm_user_signup($user_name, $user_email);
571         return true;
572 }
573
574 /**
575  * New user signup confirmation
576  *
577  * @since MU
578  *
579  * @param string $user_name The username
580  * @param string $user_email The user's email address
581  */
582 function confirm_user_signup($user_name, $user_email) {
583         ?>
584         <h2><?php /* translators: %s: username */
585         printf( __( '%s is your new username' ), $user_name) ?></h2>
586         <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ) ?></p>
587         <p><?php /* translators: %s: email address */
588         printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' ); ?></p>
589         <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
590         <?php
591         /** This action is documented in wp-signup.php */
592         do_action( 'signup_finished' );
593 }
594
595 /**
596  * Setup the new site signup
597  *
598  * @since MU
599  *
600  * @param string $user_name The username
601  * @param string $user_email The user's email address
602  * @param string $blogname The site name
603  * @param string $blog_title The site title
604  * @param array $errors
605  */
606 function signup_blog($user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '') {
607         if ( !is_wp_error($errors) )
608                 $errors = new WP_Error();
609
610         $signup_blog_defaults = array(
611                 'user_name'  => $user_name,
612                 'user_email' => $user_email,
613                 'blogname'   => $blogname,
614                 'blog_title' => $blog_title,
615                 'errors'     => $errors
616         );
617
618         /**
619          * Filter the default site creation variables for the site sign-up form.
620          *
621          * @since 3.0.0
622          *
623          * @param array $signup_blog_defaults {
624          *     An array of default site creation variables.
625          *
626          *     @type string $user_name  The user username.
627          *     @type string $user_email The user email address.
628          *     @type string $blogname   The blogname.
629          *     @type string $blog_title The title of the site.
630          *     @type array  $errors     An array of possible errors relevant to new site creation variables.
631          * }
632          */
633         $filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults );
634
635         $user_name = $filtered_results['user_name'];
636         $user_email = $filtered_results['user_email'];
637         $blogname = $filtered_results['blogname'];
638         $blog_title = $filtered_results['blog_title'];
639         $errors = $filtered_results['errors'];
640
641         if ( empty($blogname) )
642                 $blogname = $user_name;
643         ?>
644         <form id="setupform" method="post" action="wp-signup.php">
645                 <input type="hidden" name="stage" value="validate-blog-signup" />
646                 <input type="hidden" name="user_name" value="<?php echo esc_attr($user_name) ?>" />
647                 <input type="hidden" name="user_email" value="<?php echo esc_attr($user_email) ?>" />
648                 <?php
649                 /** This action is documented in wp-signup.php */
650                 do_action( 'signup_hidden_fields', 'validate-site' );
651                 ?>
652                 <?php show_blog_form($blogname, $blog_title, $errors); ?>
653                 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e('Signup') ?>" /></p>
654         </form>
655         <?php
656 }
657
658 /**
659  * Validate new site signup
660  *
661  * @since MU
662  *
663  * @return bool True if the site signup was validated, false if error
664  */
665 function validate_blog_signup() {
666         // Re-validate user info.
667         $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
668         $user_name = $user_result['user_name'];
669         $user_email = $user_result['user_email'];
670         $user_errors = $user_result['errors'];
671
672         if ( $user_errors->get_error_code() ) {
673                 signup_user( $user_name, $user_email, $user_errors );
674                 return false;
675         }
676
677         $result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] );
678         $domain = $result['domain'];
679         $path = $result['path'];
680         $blogname = $result['blogname'];
681         $blog_title = $result['blog_title'];
682         $errors = $result['errors'];
683
684         if ( $errors->get_error_code() ) {
685                 signup_blog($user_name, $user_email, $blogname, $blog_title, $errors);
686                 return false;
687         }
688
689         $public = (int) $_POST['blog_public'];
690         $signup_meta = array ('lang_id' => 1, 'public' => $public);
691
692         // Handle the language setting for the new site.
693         if ( ! empty( $_POST['WPLANG'] ) ) {
694
695                 $languages = signup_get_available_languages();
696
697                 if ( in_array( $_POST['WPLANG'], $languages ) ) {
698                         $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
699
700                         if ( $language ) {
701                                 $signup_meta['WPLANG'] = $language;
702                         }
703                 }
704
705         }
706
707         /** This filter is documented in wp-signup.php */
708         $meta = apply_filters( 'add_signup_meta', $signup_meta );
709
710         wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
711         confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
712         return true;
713 }
714
715 /**
716  * New site signup confirmation
717  *
718  * @since MU
719  *
720  * @param string $domain The domain URL
721  * @param string $path The site root path
722  * @param string $blog_title The new site title
723  * @param string $user_name The user's username
724  * @param string $user_email The user's email address
725  * @param array $meta Any additional meta from the 'add_signup_meta' filter in validate_blog_signup()
726  */
727 function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
728         ?>
729         <h2><?php /* translators: %s: site address */
730         printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
731
732         <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ) ?></p>
733         <p><?php /* translators: %s: email address */
734         printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' ); ?></p>
735         <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
736         <h2><?php _e( 'Still waiting for your email?' ); ?></h2>
737         <p>
738                 <?php _e( 'If you haven&#8217;t received your email yet, there are a number of things you can do:' ) ?>
739                 <ul id="noemail-tips">
740                         <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>
741                         <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ) ?></p></li>
742                         <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>
743                 </ul>
744         </p>
745         <?php
746         /** This action is documented in wp-signup.php */
747         do_action( 'signup_finished' );
748 }
749
750 /**
751  * Retrieves languages available during the site/user signup process.
752  *
753  * @since 4.4.0
754  *
755  * @see get_available_languages()
756  *
757  * @return array List of available languages.
758  */
759 function signup_get_available_languages() {
760         /**
761          * Filter the list of available languages for front-end site signups.
762          *
763          * Passing an empty array to this hook will disable output of the setting on the
764          * signup form, and the default language will be used when creating the site.
765          *
766          * Languages not already installed will be stripped.
767          *
768          * @since 4.4.0
769          *
770          * @param array $available_languages Available languages.
771          */
772         $languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() );
773
774         /*
775          * Strip any non-installed languages and return.
776          *
777          * Re-call get_available_languages() here in case a language pack was installed
778          * in a callback hooked to the 'signup_get_available_languages' filter before this point.
779          */
780         return array_intersect_assoc( $languages, get_available_languages() );
781 }
782
783 // Main
784 $active_signup = get_site_option( 'registration', 'none' );
785 /**
786  * Filter the type of site sign-up.
787  *
788  * @since 3.0.0
789  *
790  * @param string $active_signup String that returns registration type. The value can be
791  *                              'all', 'none', 'blog', or 'user'.
792  */
793 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
794
795 // Make the signup type translatable.
796 $i18n_signup['all'] = _x('all', 'Multisite active signup type');
797 $i18n_signup['none'] = _x('none', 'Multisite active signup type');
798 $i18n_signup['blog'] = _x('blog', 'Multisite active signup type');
799 $i18n_signup['user'] = _x('user', 'Multisite active signup type');
800
801 if ( is_super_admin() )
802         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>';
803
804 $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
805
806 $current_user = wp_get_current_user();
807 if ( $active_signup == 'none' ) {
808         _e( 'Registration has been disabled.' );
809 } elseif ( $active_signup == 'blog' && !is_user_logged_in() ) {
810         $login_url = wp_login_url( network_site_url( 'wp-signup.php' ) );
811         echo sprintf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
812 } else {
813         $stage = isset( $_POST['stage'] ) ?  $_POST['stage'] : 'default';
814         switch ( $stage ) {
815                 case 'validate-user-signup' :
816                         if ( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
817                                 validate_user_signup();
818                         else
819                                 _e( 'User registration has been disabled.' );
820                 break;
821                 case 'validate-blog-signup':
822                         if ( $active_signup == 'all' || $active_signup == 'blog' )
823                                 validate_blog_signup();
824                         else
825                                 _e( 'Site registration has been disabled.' );
826                         break;
827                 case 'gimmeanotherblog':
828                         validate_another_blog_signup();
829                         break;
830                 case 'default':
831                 default :
832                         $user_email = isset( $_POST[ 'user_email' ] ) ? $_POST[ 'user_email' ] : '';
833                         /**
834                          * Fires when the site sign-up form is sent.
835                          *
836                          * @since 3.0.0
837                          */
838                         do_action( 'preprocess_signup_form' );
839                         if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) )
840                                 signup_another_blog($newblogname);
841                         elseif ( ! is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'user' ) )
842                                 signup_user( $newblogname, $user_email );
843                         elseif ( ! is_user_logged_in() && ( $active_signup == 'blog' ) )
844                                 _e( 'Sorry, new registrations are not allowed at this time.' );
845                         else
846                                 _e( 'You are logged in already. No need to register again!' );
847
848                         if ( $newblogname ) {
849                                 $newblog = get_blogaddress_by_name( $newblogname );
850
851                                 if ( $active_signup == 'blog' || $active_signup == 'all' )
852                                         /* translators: %s: site address */
853                                         printf( '<p><em>' . __( 'The site you were looking for, %s, does not exist, but you can create it now!' ) . '</em></p>',
854                                                 '<strong>' . $newblog . '</strong>'
855                                         );
856                                 else
857                                         /* translators: %s: site address */
858                                         printf( '<p><em>' . __( 'The site you were looking for, %s, does not exist.' ) . '</em></p>',
859                                                 '<strong>' . $newblog . '</strong>'
860                                         );
861                         }
862                         break;
863         }
864 }
865 ?>
866 </div>
867 </div>
868 <?php
869 /**
870  * Fires after the sign-up forms, before wp_footer.
871  *
872  * @since 3.0.0
873  */
874 do_action( 'after_signup_form' ); ?>
875
876 <?php get_footer( 'wp-signup' );