root/trunk/wp-signup.php

Revision 1393, 17.6 kB (checked in by donncha, 3 months ago)

Only show the "create it now!" message when blog registration is enabled, fixes #628, props lambic

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