[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress MU Trunk

Provided by Yoast

title

Body

[close]

/ -> wp-signup.php (source)

   1  <?php
   2  
   3  /** Sets up the WordPress Environment. */

   4  require( dirname(__FILE__) . '/wp-load.php' );
   5  
   6  add_action( 'wp_head', 'signuppageheaders' ) ;
   7  
   8  require ( 'wp-blog-header.php' );
   9  require_once( ABSPATH . WPINC . '/registration.php' );
  10  
  11  if( is_array( get_site_option( 'illegal_names' )) && $_GET[ 'new' ] != '' && in_array( $_GET[ 'new' ], get_site_option( 'illegal_names' ) ) == true ) {
  12      wp_redirect( "http://{$current_site->domain}{$current_site->path}" );
  13      die();
  14  }
  15  
  16  function do_signup_header() {
  17      do_action("signup_header");
  18  }
  19  add_action( 'wp_head', 'do_signup_header' );
  20  
  21  function signuppageheaders() {
  22      echo "<meta name='robots' content='noindex,nofollow' />\n";
  23  }
  24  
  25  if( $current_blog->domain . $current_blog->path != $current_site->domain . $current_site->path ) {
  26      wp_redirect( "http://" . $current_site->domain . $current_site->path . "wp-signup.php" );
  27      die();
  28  }
  29  
  30  function wpmu_signup_stylesheet() {
  31      ?>
  32      <style type="text/css">    
  33          .mu_register { width: 90%; margin:0 auto; }
  34          .mu_register form { margin-top: 2em; }
  35          .mu_register .error { font-weight:700; padding:10px; color:#333333; background:#FFEBE8; border:1px solid #CC0000; }
  36          .mu_register input[type="submit"],
  37              .mu_register #blog_title,
  38              .mu_register #user_email, 
  39              .mu_register #blogname,
  40              .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }    
  41          .mu_register .prefix_address,
  42              .mu_register .suffix_address {font-size: 18px;display:inline; }            
  43          .mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
  44          .mu_register label.checkbox { display:inline; }
  45          .mu_register .mu_alert { font-weight:700; padding:10px; color:#333333; background:#ffffe0; border:1px solid #e6db55; }
  46      </style>
  47      <?php
  48  }
  49  
  50  add_action( 'wp_head', 'wpmu_signup_stylesheet' );
  51  get_header();
  52  ?>
  53  <div id="content" class="widecolumn">
  54  <div class="mu_register">
  55  <?php
  56  function show_blog_form($blogname = '', $blog_title = '', $errors = '') {
  57      global $current_site;
  58      // Blog name

  59      if( constant( "VHOST" ) == 'no' )
  60          echo '<label for="blogname">' . __('Blog Name:') . '</label>';
  61      else
  62          echo '<label for="blogname">' . __('Blog Domain:') . '</label>';
  63  
  64      if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
  65          <p class="error"><?php echo $errmsg ?></p>
  66      <?php }
  67  
  68      if( constant( "VHOST" ) == 'no' ) {
  69          echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
  70      } else {
  71          echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
  72      }
  73      if ( !is_user_logged_in() ) {
  74          print '(<strong>' . __( 'Your address will be ' );
  75          if( constant( "VHOST" ) == 'no' ) {
  76              print $current_site->domain . $current_site->path . __( 'blogname' );
  77          } else {
  78              print __( 'domain.' ) . $current_site->domain . $current_site->path;
  79          }
  80          echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' ) . '</p>';
  81      }
  82  
  83      // Blog Title

  84      ?>
  85      <label for="blog_title"><?php _e('Blog Title:') ?></label>    
  86      <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
  87          <p class="error"><?php echo $errmsg ?></p>
  88      <?php }
  89      echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
  90      ?>
  91  
  92      <div id="privacy">
  93          <p class="privacy-intro">
  94              <label for="blog_public_on"><?php _e('Privacy:') ?></label>
  95              <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.'); ?> 
  96              <div style="clear:both;"></div>
  97              <label class="checkbox" for="blog_public_on">
  98                  <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 } ?> />
  99                  <strong><?php _e( 'Yes' ); ?></strong>
 100              </label>
 101              <label class="checkbox" for="blog_public_off">
 102                  <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 } ?> />
 103                  <strong><?php _e( 'No' ); ?></strong>
 104              </label>
 105          </p>
 106      </div>
 107      
 108      <?php
 109      do_action('signup_blogform', $errors);
 110  }
 111  
 112  function validate_blog_form() {
 113      $user = '';
 114      if ( is_user_logged_in() )
 115          $user = wp_get_current_user();
 116  
 117      return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
 118  }
 119  
 120  function show_user_form($user_name = '', $user_email = '', $errors = '') {
 121      // User name

 122      echo '<label for="user_name">' . __('Username:') . '</label>';
 123      if ( $errmsg = $errors->get_error_message('user_name') ) {
 124          echo '<p class="error">'.$errmsg.'</p>';
 125      }
 126      echo '<input name="user_name" type="text" id="user_name" value="'.$user_name.'" maxlength="50" /><br />';
 127      _e('(Must be at least 4 characters, letters and numbers only.)');
 128      ?>
 129  
 130      <label for="user_email"><?php _e('Email&nbsp;Address:') ?></label>
 131      <?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
 132          <p class="error"><?php echo $errmsg ?></p>
 133      <?php } ?>        
 134      <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>.)') ?>
 135      <?php
 136      if ( $errmsg = $errors->get_error_message('generic') ) {
 137          echo '<p class="error">'.$errmsg.'</p>';
 138      }
 139      do_action( 'signup_extra_fields', $errors );
 140  }
 141  
 142  function validate_user_form() {
 143      return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
 144  }
 145  
 146  function signup_another_blog($blogname = '', $blog_title = '', $errors = '') {
 147      global $current_user, $current_site;
 148      
 149      if ( ! is_wp_error($errors) ) {
 150          $errors = new WP_Error();
 151      }
 152  
 153      // allow definition of default variables

 154      $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
 155      $blogname = $filtered_results['blogname'];
 156      $blog_title = $filtered_results['blog_title'];
 157      $errors = $filtered_results['errors'];
 158  
 159      echo '<h2>' . sprintf( __('Get <em>another</em> %s blog in seconds'), $current_site->site_name ) . '</h2>';
 160  
 161      if ( $errors->get_error_code() ) {
 162          echo "<p>" . __('There was a problem, please correct the form below and try again.') . "</p>";
 163      }
 164      ?>
 165      <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>
 166      
 167      <?php
 168      $blogs = get_blogs_of_user($current_user->ID);    
 169      if ( !empty($blogs) ) { ?>
 170          <p>
 171              <?php _e('Blogs you are already a member of:') ?>
 172              <ul>
 173                  <?php foreach ( $blogs as $blog ) {
 174                      echo "<li><a href='http://" . $blog->domain . $blog->path . "'>" . $blog->domain . $blog->path . "</a></li>";
 175                  } ?>
 176              </ul>
 177          </p>
 178      <?php } ?>
 179      
 180      <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>
 181      <form id="setupform" method="post" action="wp-signup.php">
 182          <input type="hidden" name="stage" value="gimmeanotherblog" />
 183          <?php do_action( "signup_hidden_fields" ); ?>
 184          <?php show_blog_form($blogname, $blog_title, $errors); ?>
 185          <p class="submit"><input type="submit" name="submit" class="submit" value="<?php _e('Create Blog &raquo;') ?>" /></p>
 186      </form>
 187      <?php
 188  }
 189  
 190  function validate_another_blog_signup() {
 191      global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
 192      $current_user = wp_get_current_user();
 193      if( !is_user_logged_in() )
 194          die();
 195  
 196      $result = validate_blog_form();
 197      extract($result);
 198  
 199      if ( $errors->get_error_code() ) {
 200          signup_another_blog($blogname, $blog_title, $errors);
 201          return false;
 202      }
 203  
 204      $public = (int) $_POST['blog_public'];
 205      $meta = apply_filters('signup_create_blog_meta', array ('lang_id' => 1, 'public' => $public)); // depreciated

 206      $meta = apply_filters( "add_signup_meta", $meta );
 207  
 208      wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
 209      confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
 210      return true;
 211  }
 212  
 213  function confirm_another_blog_signup($domain, $path, $blog_title, $user_name, $user_email = '', $meta = '') {
 214      ?>
 215      <h2><?php printf(__('The blog %s is yours.'), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
 216      <p>
 217          <?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) ?>
 218      </p>
 219      <?php
 220      do_action('signup_finished');
 221  }
 222  
 223  function signup_user($user_name = '', $user_email = '', $errors = '') {
 224      global $current_site, $active_signup;
 225  
 226      if ( !is_wp_error($errors) )
 227          $errors = new WP_Error();
 228      if( isset( $_POST[ 'signup_for' ] ) ) {
 229          $signup[ wp_specialchars( $_POST[ 'signup_for' ] ) ] = 'checked="checked"';
 230      } else {
 231          $signup[ 'blog' ] = 'checked="checked"';
 232      }
 233  
 234      // allow definition of default variables

 235      $filtered_results = apply_filters('signup_user_init', array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors ));
 236      $user_name = $filtered_results['user_name'];
 237      $user_email = $filtered_results['user_email'];
 238      $errors = $filtered_results['errors'];
 239  
 240      ?>
 241      
 242      <h2><?php printf( __('Get your own %s account in seconds'), $current_site->site_name ) ?></h2>
 243      <form id="setupform" method="post" action="wp-signup.php">
 244          <input type="hidden" name="stage" value="validate-user-signup" />
 245          <?php do_action( "signup_hidden_fields" ); ?>
 246          <?php show_user_form($user_name, $user_email, $errors); ?>
 247          
 248          <p>
 249          <?php if( $active_signup == 'blog' ) { ?>
 250              <input id="signupblog" type="hidden" name="signup_for" value="blog" />
 251          <?php } elseif( $active_signup == 'user' ) { ?>
 252              <input id="signupblog" type="hidden" name="signup_for" value="user" />
 253          <?php } else { ?>
 254              <input id="signupblog" type="radio" name="signup_for" value="blog" <?php echo $signup['blog'] ?> />
 255              <label class="checkbox" for="signupblog"><?php _e('Gimme a blog!') ?></label>    
 256              <br />            
 257              <input id="signupuser" type="radio" name="signup_for" value="user" <?php echo $signup['user'] ?> />            
 258              <label class="checkbox" for="signupuser"><?php _e('Just a username, please.') ?></label>
 259          <?php } ?>
 260          </p>
 261          
 262          <p class="submit"><input type="submit" name="submit" class="submit" value="<?php _e('Next &raquo;') ?>" /></p>
 263      </form>
 264      <?php
 265  }
 266  
 267  function validate_user_signup() {
 268      $result = validate_user_form();
 269      extract($result);
 270  
 271      if ( $errors->get_error_code() ) {
 272          signup_user($user_name, $user_email, $errors);
 273          return false;
 274      }
 275  
 276      if ( 'blog' == $_POST['signup_for'] ) {
 277          signup_blog($user_name, $user_email);
 278          return false;
 279      }
 280  
 281      wpmu_signup_user($user_name, $user_email, apply_filters( "add_signup_meta", array() ) );
 282  
 283      confirm_user_signup($user_name, $user_email);
 284      return true;
 285  }
 286  
 287  function confirm_user_signup($user_name, $user_email) {
 288      ?>
 289      <h2><?php printf(__('%s is your new username'), $user_name) ?></h2>
 290      <p><?php _e('But, before you can start using your new username, <strong>you must activate it</strong>.') ?></p>
 291      <p><?php printf(__('Check your inbox at <strong>%1$s</strong> and click the link given.'),  $user_email) ?></p>
 292      <p><?php _e('If you do not activate your username within two days, you will have to sign up again.'); ?></p>
 293      <?php
 294      do_action('signup_finished');
 295  }
 296  
 297  function signup_blog($user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '') {
 298      if ( !is_wp_error($errors) )
 299          $errors = new WP_Error();
 300  
 301      // allow definition of default variables

 302      $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
 303      $user_name = $filtered_results['user_name'];
 304      $user_email = $filtered_results['user_email'];
 305      $blogname = $filtered_results['blogname'];
 306      $blog_title = $filtered_results['blog_title'];
 307      $errors = $filtered_results['errors'];
 308  
 309      if ( empty($blogname) )
 310          $blogname = $user_name;
 311      ?>
 312      <form id="setupform" method="post" action="wp-signup.php">
 313          <input type="hidden" name="stage" value="validate-blog-signup" />
 314          <input type="hidden" name="user_name" value="<?php echo $user_name ?>" />
 315          <input type="hidden" name="user_email" value="<?php echo $user_email ?>" />
 316          <?php do_action( "signup_hidden_fields" ); ?>
 317          <?php show_blog_form($blogname, $blog_title, $errors); ?>
 318          <p class="submit"><input type="submit" name="submit" class="submit" value="<?php _e('Signup &raquo;') ?>" /></p>
 319      </form>
 320      <?php
 321  }
 322  
 323  function validate_blog_signup() {
 324      // Re-validate user info.

 325      $result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
 326      extract($result);
 327  
 328      if ( $errors->get_error_code() ) {
 329          signup_user($user_name, $user_email, $errors);
 330          return false;
 331      }
 332  
 333      $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']);
 334      extract($result);
 335  
 336      if ( $errors->get_error_code() ) {
 337          signup_blog($user_name, $user_email, $blogname, $blog_title, $errors);
 338          return false;
 339      }
 340  
 341      $public = (int) $_POST['blog_public'];
 342      $meta = array ('lang_id' => 1, 'public' => $public);
 343      $meta = apply_filters( "add_signup_meta", $meta );
 344  
 345      wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
 346      confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
 347      return true;
 348  }
 349  
 350  function confirm_blog_signup($domain, $path, $blog_title, $user_name = '', $user_email = '', $meta) {
 351      ?>
 352      <h2><?php printf(__('Congratulations! Your new blog, %s, is almost ready.'), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) ?></h2>
 353      
 354      <p><?php _e('But, before you can start using your blog, <strong>you must activate it</strong>.') ?></p>
 355      <p><?php printf(__('Check your inbox at <strong>%s</strong> and click the link given. It should arrive within 30 minutes.'),  $user_email) ?></p>
 356      <p><?php _e('If you do not activate your blog within two days, you will have to sign up again.'); ?></p>
 357      <h2><?php _e('Still waiting for your email?'); ?></h2>
 358      <p>
 359          <?php _e("If you haven't received your email yet, there are a number of things you can do:") ?>
 360          <ul id="noemail-tips">
 361              <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>
 362              <li><p><?php _e('Check the junk email or spam folder of your email client.  Sometime emails wind up there by mistake.') ?></p></li>
 363              <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>
 364          </ul>
 365      </p>
 366      <?php
 367      do_action('signup_finished');
 368  }
 369  
 370  // Main

 371  $active_signup = get_site_option( 'registration' );
 372  if( !$active_signup )
 373      $active_signup = 'all';
 374  
 375  $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"

 376  
 377  if( is_site_admin() ) {
 378      echo '<div class="mu_alert"><p>' . 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 ) . '</p>';
 379      if ( function_exists( 'cfc_stylesheet_html' ) == false && function_exists( 'wphc_option' ) == false )
 380          echo '<p>' . __( 'Spam is a huge problem on the Internet. Protect your site by using <a href="http://wordpress-plugins.feifei.us/hashcash/">WP-Hashcash</a>, <a href="http://ocaoimh.ie/cookies-for-comments/">Cookies For Comments</a> or follow <a href="http://www.darcynorman.net/2009/05/20/stopping-spamblog-registration-in-wordpress-multiuser/">this advice</a>. They should help stop or slow down those who create spam blogs on your site.' ) . '</p>';
 381      echo '</div>';
 382  }
 383  
 384  $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
 385  
 386  $current_user = wp_get_current_user();
 387  if( $active_signup == "none" ) {
 388      echo '<p>' . __( "Registration has been disabled." ) . '</p>';
 389  } elseif( $active_signup == 'blog' && !is_user_logged_in() ){
 390      if( is_ssl() ) {
 391          $proto = 'https://';
 392      } else {
 393          $proto = 'http://';
 394      }
 395      $login_url = site_url( 'wp-login.php?redirect_to=' . urlencode($proto . $_SERVER['HTTP_HOST'] . '/wp-signup.php' ));
 396      echo sprintf( __( "You must first <a href=\"%s\">login</a>, and then you can create a new blog."), $login_url );
 397  } else {
 398      switch ($_POST['stage']) {
 399          case 'validate-user-signup' :
 400              if( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
 401                  validate_user_signup();
 402              else
 403                  _e( "User registration has been disabled." );
 404          break;
 405          case 'validate-blog-signup':
 406              if( $active_signup == 'all' || $active_signup == 'blog' )
 407                  validate_blog_signup();
 408              else
 409                  _e( "Blog registration has been disabled." );
 410              break;
 411          case 'gimmeanotherblog':
 412              validate_another_blog_signup();
 413              break;
 414          default :
 415              $user_email = $_POST[ 'user_email' ];
 416              do_action( "preprocess_signup_form" ); // populate the form from invites, elsewhere?

 417              if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) ) {
 418                  signup_another_blog($newblogname);
 419              } elseif( is_user_logged_in() == false && ( $active_signup == 'all' || $active_signup == 'user' ) ) {
 420                  signup_user( $newblogname, $user_email );
 421              } elseif( is_user_logged_in() == false && ( $active_signup == 'blog' ) ) {
 422                  _e( "I'm sorry. We're not accepting new registrations at this time." );
 423              } else {
 424                  _e( "You're logged in already. No need to register again!" );
 425              }
 426              if ($newblogname) {
 427                  if( constant( "VHOST" ) == 'no' )
 428                      $newblog = 'http://' . $current_site->domain . $current_site->path . $newblogname . '/';
 429                  else
 430                      $newblog = 'http://' . $newblogname . '.' . $current_site->domain . $current_site->path;
 431                  if ($active_signup == 'blog' || $active_signup == 'all')
 432                      printf(__("<p><em>The blog you were looking for, <strong>%s</strong> doesn't exist but you can create it now!</em></p>"), $newblog );
 433                  else
 434                      printf(__("<p><em>The blog you were looking for, <strong>%s</strong> doesn't exist.</em></p>"), $newblog );
 435              }
 436              break;
 437      }
 438  }
 439  ?>
 440  </div>
 441  </div>
 442  
 443  <?php get_footer(); ?>


Generated: Wed Jun 9 08:50:41 2010 Cross-referenced by PHPXref 0.7