root/tags/1.5.1/wp-signup.php

Revision 1252, 17.5 kB (checked in by donncha, 8 months ago)

Pass site_id to wpmu_create_blog, should fix #577

Line 
1 <?php
2 define( "WP_INSTALLING", true );
3 require( 'wp-config.php' );
4
5 add_action( 'wp_head', 'signuppageheaders' ) ;
6
7 require( 'wp-blog-header.php' );
8 require_once( ABSPATH . WPINC . '/registration.php' );
9
10 if( is_array( get_site_option( 'illegal_names' )) && $_GET[ 'new' ] != '' && in_array( $_GET[ 'new' ], get_site_option( 'illegal_names' ) ) == true ) {
11     wp_redirect( "http://{$current_site->domain}{$current_site->path}" );
12     die();
13 }
14
15 do_action("signup_header");
16
17 function signuppageheaders() {
18     echo "<meta name='robots' content='noindex,nofollow'>\n";
19 }
20
21 if( $current_blog->domain . $current_blog->path != $current_site->domain . $current_site->path ) {
22     wp_redirect( "http://" . $current_site->domain . $current_site->path . "wp-signup.php" );
23     die();
24 }
25
26 function wpmu_signup_stylesheet() {
27 ?>
28 <style type="text/css">
29 form { margin-top: 2em; }
30 #submit, #blog_title, #user_email {
31     width: 90%;
32     font-size: 24px;
33 }
34 .error {
35     background-color: #f66;
36 }
37 </style>
38 <?php
39 }
40
41 add_action( 'wp_head', 'wpmu_signup_stylesheet' );
42 get_header();
43 ?>
44 <div id="content" class="widecolumn">
45 <?php
46 function show_blog_form($blog_id = '', $blog_title = '', $errors = '') {
47     global $current_site;
48     $locale = get_locale();
49
50     // Blog name/Username
51     if ( $errors->get_error_message('blog_id') )
52         print '<tr class="error">';
53     else
54         print '<tr>';
55
56     if( constant( "VHOST" ) == 'no' )
57         echo '<th valign="top">' . __('Blog Name:') . '</th><td>';
58     else
59         echo '<th valign="top">' . __('Blog Domain:') . '</th><td>';
60
61     if ( $errmsg = $errors->get_error_message('blog_id') ) {
62         ?><p><strong><?php echo $errmsg ?></strong></p><?php
63     }
64     if( constant( "VHOST" ) == 'no' ) {
65         print '<span style="font-size: 20px">' . $current_site->domain . $current_site->path . '</span><input name="blog_id" type="text" id="blog_id" value="'.$blog_id.'" maxlength="50" style="width:40%; text-align: left; font-size: 20px;" /><br />';
66     } else {
67         print '<input name="blog_id" type="text" id="blog_id" value="'.$blog_id.'" maxlength="50" style="width:40%; text-align: right; font-size: 20px;" /><span style="font-size: 20px">.' . $current_site->domain . $current_site->path . '</span><br />';
68     }
69     if ( !is_user_logged_in() ) {
70         print '(<strong>' . __( 'Your address will be ' );
71         if( constant( "VHOST" ) == 'no' ) {
72             print $current_site->domain . $current_site->path . __( 'blogname' );
73         } else {
74             print __( 'domain.' ) . $current_site->domain . $current_site->path;
75         }
76         print '.</strong>' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' ) . '</td> </tr>';
77     }
78
79     // Blog Title
80     if ( $errors->get_error_message('blog_title')) {
81         print '<tr class="error">';
82     } else {
83         print '<tr>';
84     }
85 ?><th valign="top" width="120"><?php _e('Blog Title:') ?></th><td><?php
86
87     if ( $errmsg = $errors->get_error_message('blog_title') ) {
88 ?><p><strong><?php echo $errmsg ?></strong></p><?php
89     }
90     print '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></td>
91         </tr>';
92 ?>
93 <tr>
94 <th scope="row"  valign="top"><?php _e('Privacy:') ?></th>
95 <td><?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.'); ?>
96 <label><input type="radio" name="blog_public" value="1" <?php if( !isset( $_POST[ 'blog_public' ] ) || $_POST[ 'blog_public' ] == '1' ) { ?>checked="checked"<?php } ?> /> <strong><?php _e( 'Yes' ); ?></strong> </label> <label><input type="radio" name="blog_public" value="0" <?php if( isset( $_POST[ 'blog_public' ] ) && $_POST[ 'blog_public' ] == '0' ) { ?>checked="checked"<?php } ?> /><strong><?php _e( 'No' ); ?></strong> </label> <br />
97 </tr>
98 <?php
99 do_action('signup_blogform', $errors);
100 }
101
102 function validate_blog_form() {
103     if ( is_user_logged_in() )
104         $user = wp_get_current_user();
105     else
106         $user = '';
107
108     $result = wpmu_validate_blog_signup($_POST['blog_id'], $_POST['blog_title'], $user);
109
110     return $result;
111 }
112
113 function show_user_form($user_name = '', $user_email = '', $errors = '') {
114     // Blog name/Username
115     if ( $errors->get_error_message('user_name') ) {
116         print '<tr class="error">';
117     } else {
118         print '<tr>';
119     }
120
121     echo '<th valign="top">' . __('Username:') . '</th><td>';
122
123     if ( $errmsg = $errors->get_error_message('user_name') ) {
124         ?><p><strong><?php echo $errmsg ?></strong></p><?php
125     }
126
127     print '<input name="user_name" type="text" id="user_name" value="'.$user_name.'" maxlength="50" style="width:50%; font-size: 30px;" /><br />';
128     _e('(Must be at least 4 characters, letters and numbers only.)'); echo '</td> </tr>';
129
130     // User Email
131     if ( $errors->get_error_message('user_email') ) {
132         print '<tr class="error">';
133     } else {
134         print '<tr>';
135     }
136 ?><th valign="top"><?php _e('Email&nbsp;Address:') ?></th><td valign="top"><?php
137
138     if ( $errmsg = $errors->get_error_message('user_email') ) {
139 ?><p><strong><?php echo $errmsg ?></strong></p><?php
140     }
141     ?>
142     <input name="user_email" type="text" id="user_email" value="<?php  echo wp_specialchars($user_email, 1) ?>" maxlength="200" /><br /><?php _e('(We&#8217;ll send your password to this address, so <strong>triple-check it</strong>.)') ?></td>
143     </tr>
144     <?php
145     if ( $errmsg = $errors->get_error_message('generic') )
146         print '<tr class="error"> <th colspan="2">'.$errmsg.'</th> </tr>';
147     do_action( 'signup_extra_fields', $errors );
148 }
149
150 function validate_user_form() {
151     $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
152
153     return $result;
154 }
155
156 function signup_another_blog($blog_id = '', $blog_title = '', $errors = '') {
157     global $current_user, $wpdb, $domain, $current_site;
158
159     if ( ! is_wp_error($errors) )
160         $errors = new WP_Error();
161
162     // allow definition of default variables
163     $filtered_results = apply_filters('signup_another_blog_init', array('blog_id' => $blog_id, 'blog_title' => $blog_title, 'errors' => $errors ));
164     $blog_id = $filtered_results['blog_id'];
165     $blog_title = $filtered_results['blog_title'];
166     $errors = $filtered_results['errors'];
167
168     echo '<h2>' . sprintf( __('Get <em>another</em> %s blog in seconds'), $current_site->site_name ) . '</h2>';
169
170     if ( $errors->get_error_code() ) {
171         echo "<p>" . __('There was a problem, please correct the form below and try again.') . "</p>";
172     }
173
174 ?>
175 <p><?php printf(__("Welcome back, %s. By filling out the form below, you can <strong>add another blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly."), $current_user->display_name) ?></p>
176 <?php
177     $blogs = get_blogs_of_user($current_user->ID);
178
179     if ( ! empty($blogs) ) {
180         ?><p><?php _e('Here are the blogs you already have:') ?></p><ul><?php
181         foreach ( $blogs as $blog )
182             echo "<li><a href='http://" . $blog->domain . $blog->path . "'>" . $blog->domain . $blog->path . "</a></li>";
183         ?></ul><?php
184     }
185 ?>
186 <p><?php _e("If you&#8217;re not going to use a great blog domain, leave it for a new user. Now have at it!") ?></p>
187 <form name="setupform" id="setupform" method="post" action="wp-signup.php">
188 <input type="hidden" name="stage" value="gimmeanotherblog" />
189 <?php do_action( "signup_hidden_fields" ); ?>
190 <table border="0" width="100%" cellpadding="9">
191 <?php
192     show_blog_form($blog_id, $blog_title, $errors);
193 ?>
194 <tr>
195 <th scope="row"  valign="top">&nbsp;</th>
196 <td><input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Create Blog &raquo;') ?>" /></td>
197 </tr>
198 </table>
199 </form>
200 <?php
201 }
202
203 function validate_another_blog_signup() {
204     global $wpdb, $current_user, $blog_id, $blog_title, $errors, $domain, $path;
205     $current_user = wp_get_current_user();
206     if( !is_user_logged_in() )
207         die();
208
209     $result = validate_blog_form();
210     extract($result);
211
212     if ( $errors->get_error_code() ) {
213         signup_another_blog($blog_id, $blog_title, $errors);
214         return;
215     }
216
217     $public = (int) $_POST['blog_public'];
218     $meta = apply_filters('signup_create_blog_meta', array ('lang_id' => 1, 'public' => $public));
219
220     wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
221     confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
222 }
223
224 function confirm_another_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta) {
225 ?>
226 <h2><?php printf(__('The blog, %s, is yours.'), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
227 <p><?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog.  <a href="%3$s">Login</a> as "%4$s" using your existing password.'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?></p>
228 <?php
229     do_action('signup_finished');
230 }
231
232 function signup_user($user_name = '', $user_email = '', $errors = '') {
233     global $current_site, $active_signup;
234
235     if ( ! is_wp_error($errors) )
236         $errors = new WP_Error();
237     if( isset( $_POST[ 'signup_for' ] ) ) {
238         $signup[ wp_specialchars( $_POST[ 'signup_for' ] ) ] = 'checked="checked"';
239     } else {
240         $signup[ 'blog' ] = 'checked="checked"';
241     }
242
243     // allow definition of default variables
244     $filtered_results = apply_filters('signup_user_init', array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors ));
245     $user_name = $filtered_results['user_name'];
246     $user_email = $filtered_results['user_email'];
247     $errors = $filtered_results['errors'];
248 ?>
249 <h2><?php printf( __('Get your own %s account in seconds'), $current_site->site_name ) ?></h2>
250 <form name="setupform" id="setupform" method="post" action="wp-signup.php">
251 <input type="hidden" name="stage" value="validate-user-signup" />
252 <?php do_action( "signup_hidden_fields" ); ?>
253 <table border="0" width="100%" cellpadding="9" cellspacing="4">
254 <?php show_user_form($user_name, $user_email, $errors); ?>
255 <tr>
256 <th scope="row"  valign="top">&nbsp;</th>
257 <td>
258 <p>
259 <?php if( $active_signup == 'blog' ) { ?>
260 <input id="signupblog" type="hidden" name="signup_for" value="blog" />
261 <?php } elseif( $active_signup == 'user' ) { ?>
262 <input id="signupblog" type="hidden" name="signup_for" value="user" />
263 <?php } else { ?>
264 <input id="signupblog" type="radio" name="signup_for" value="blog" <?php echo $signup[ 'blog' ] ?> />
265 <label for="signupblog"><?php _e('Gimme a blog!') ?></label>
266 <br />
267 <input id="signupuser" type="radio" name="signup_for" value="user" <?php echo $signup[ 'user' ] ?> />
268 <label for="signupuser"><?php _e('Just a username, please.') ?></label>
269 <?php } ?>
270 </p>
271 </td>
272 </tr>
273 <tr>
274 <th scope="row"  valign="top">&nbsp;</th>
275 <td><input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Next &raquo;') ?>" /></td>
276 </tr>
277 </table>
278 </form>
279 <?php
280
281 }
282
283 function validate_user_signup() {
284     $result = validate_user_form();
285     extract($result);
286
287     if ( $errors->get_error_code() ) {
288         signup_user($user_name, $user_email, $errors);
289         return;
290     }
291
292     if ( 'blog' == $_POST['signup_for'] ) {
293         signup_blog($user_name, $user_email);
294         return;
295     }
296
297     wpmu_signup_user($user_name, $user_email, apply_filters( "add_signup_meta", array() ) );
298
299     confirm_user_signup($user_name, $user_email);
300 }
301
302 function confirm_user_signup($user_name, $user_email) {
303 ?>
304 <h2><?php printf(__('%s is your new username'), $user_name) ?></h2>
305 <p><?php _e('But, before you can start using your new username, <strong>you must activate it</strong>.') ?></p>
306 <p><?php printf(__('Check your inbox at <strong>%1$s</strong> and click the link given.  '),  $user_email) ?></p>
307 <p><?php _e('If you do not activate your username within two days, you will have to sign up again.'); ?></p>
308 <?php
309     do_action('signup_finished');
310 }
311
312 function signup_blog($user_name = '', $user_email = '', $blog_id = '', $blog_title = '', $errors = '') {
313     if ( ! is_wp_error($errors) )
314         $errors = new WP_Error();
315
316     // allow definition of default variables
317     $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blog_id' => $blog_id, 'blog_title' => $blog_title, 'errors' => $errors ));
318     $user_name = $filtered_results['user_name'];
319     $user_email = $filtered_results['user_email'];
320     $blog_id = $filtered_results['blog_id'];
321     $blog_title = $filtered_results['blog_title'];
322     $errors = $filtered_results['errors'];
323
324     if ( empty($blog_id) )
325         $blog_id = $user_name;
326 ?>
327 <form name="setupform" id="setupform" method="post" action="wp-signup.php">
328 <input type="hidden" name="stage" value="validate-blog-signup" />
329 <input type="hidden" name="user_name" value="<?php echo $user_name ?>" />
330 <input type="hidden" name="user_email" value="<?php echo $user_email ?>" />
331 <?php do_action( "signup_hidden_fields" ); ?>
332 <table border="0" width="100%" cellpadding="9">
333 <?php show_blog_form($blog_id, $blog_title, $errors); ?>
334 <tr>
335 <th scope="row"  valign="top">&nbsp;</th>
336 <td><input id="submit" type="submit" name="Submit" class="submit" value="<?php _e('Signup &raquo;') ?>" /></td>
337 </tr>
338 </table>
339 </form>
340 <?php
341 }
342
343 function validate_blog_signup() {
344     // Re-validate user info.
345     $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
346     extract($result);
347
348     if ( $errors->get_error_code() ) {
349         signup_user($user_name, $user_email, $errors);
350         return;
351     }
352
353     $result = wpmu_validate_blog_signup($_POST['blog_id'], $_POST['blog_title']);
354     extract($result);
355
356     if ( $errors->get_error_code() ) {
357         signup_blog($user_name, $user_email, $blog_id, $blog_title, $errors);
358         return;
359     }
360
361     $public = (int) $_POST['blog_public'];
362     $meta = array ('lang_id' => 1, 'public' => $public);
363     $meta = apply_filters( "add_signup_meta", $meta );
364
365     wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
366
367     confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
368 }
369
370 function confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta) {
371 ?>
372 <h2><?php printf(__('Congratulations! Your new blog, %s, is almost ready.'), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
373 <p><?php _e('But, before you can start using your blog, <strong>you must activate it</strong>.') ?></p>
374 <p><?php printf(__('Check your inbox at <strong>%s</strong> and click the link given. It should arrive within 30 minutes.'),  $user_email) ?></p>
375 <p><?php _e('If you do not activate your blog within two days, you will have to sign up again.'); ?></p>
376 <h2><?php _e('Still waiting for your email?') ?></h2>
377 <p><?php _e("If you haven't received your email yet, there are a number of things you can do:") ?></p>
378 <ul>
379 <li><p><strong><?php _e('Wait a little longer.  Sometimes delivery of email can be delayed by precesses outside of our control.') ?></strong></p></li>
380 <li><p><?php _e('Check the junk email or spam folder of your email client.  Sometime emails wind up there by mistake.') ?></p></li>
381 <li><?php printf(__("Have you entered your email correctly?  We think it's %s but if you've entered it incorrectly, you won't receive it."), $user_email) ?></li>
382 </ul>
383 <?php
384     do_action('signup_finished');
385 }
386
387 // Main
388 $active_signup = get_site_option( 'registration' );
389 if( !$active_signup )
390     $active_signup = 'all';
391
392 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
393
394 if( is_site_admin() ) {
395     echo "<div style='background: #faf; font-weight: bold; border: 1px solid #333; margin: 2px; padding: 2px'>" . sprintf( __( "Greetings Site Administrator! You are currently allowing '%s' registrations. To change or disable registration go to your <a href='wp-admin/wpmu-options.php'>Options page</a>." ), $active_signup ) . "</div>";
396 }
397
398 $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
399
400 $current_user = wp_get_current_user();
401 if( $active_signup == "none" ) {
402     _e( "Registration has been disabled." );
403 } else {
404     if( $active_signup == 'blog' && !is_user_logged_in() ) {
405         wp_die( 'You must be logged in to register a blog.' );
406     }
407     switch ($_POST['stage']) {
408     case 'validate-user-signup' :
409         if( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
410             validate_user_signup();
411         else
412             _e( "User registration has been disabled." );
413         break;
414     case 'validate-blog-signup':
415         if( $active_signup == 'all' || $active_signup == 'blog' )
416             validate_blog_signup();
417         else
418             _e( "Blog registration has been disabled." );
419         break;
420     case 'gimmeanotherblog':
421         validate_another_blog_signup();
422         break;
423     default :
424         $user_email = $_POST[ 'user_email' ];
425         do_action( "preprocess_signup_form" ); // populate the form from invites, elsewhere?
426         if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) ) {
427             signup_another_blog($newblogname);
428         } elseif( is_user_logged_in() == false && ( $active_signup == 'all' || $active_signup == 'user' ) ) {
429             signup_user( $newblogname, $user_email );
430         } elseif( is_user_logged_in() == false && ( $active_signup == 'blog' ) ) {
431             _e( "I'm sorry. We're not accepting new registrations at this time." );
432         } else {
433             _e( "You're logged in already. No need to register again!" );
434         }
435
436         if ($newblogname) {
437             if( constant( "VHOST" ) == 'no' )
438                 $newblog = 'http://' . $current_site->domain . $current_site->path . $newblogname . '/';
439             else
440                 $newblog = 'http://' . $newblogname . '.' . $current_site->domain . $current_site->path;
441             printf(__("<p><em>The blog you were looking for, <strong>%s</strong> doesn't exist but you can create it now!</em></p>"), $newblog );
442         }
443         break;
444     }
445 }
446 ?>
447 </div>
448
449 <?php get_footer(); ?>
450
Note: See TracBrowser for help on using the browser.