[ Index ]

PHP Cross Reference of Wordpress MU 2.7

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 #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      <p>
  93          <label for="blog_public_on"><?php _e('Privacy:') ?></label>
  94          <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.'); ?> 
  95          <div style="clear:both;"></div>
  96          <label class="checkbox" for="blog_public_on">
  97              <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 } ?> />
  98              <strong><?php _e( 'Yes' ); ?></strong>
  99          </label>
 100          <label class="checkbox" for="blog_public_off">
 101              <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 } ?> />
 102              <strong><?php _e( 'No' ); ?></strong>
 103          </label>
 104      </p>
 105      
 106      <?php
 107      do_action('signup_blogform', $errors);
 108  }
 109  
 110  function validate_blog_form() {
 111      $user = '';
 112      if ( is_user_logged_in() )
 113          $user = wp_get_current_user();
 114  
 115      return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
 116  }
 117  
 118  function show_user_form($user_name = '', $user_email = '', $errors = '') {
 119      // User name

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

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

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

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

 301      $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
 302      $user_name = $filtered_results['user_name'];
 303      $user_email = $filtered_results['user_email'];
 304      $blogname = $filtered_results['blogname'];
 305      $blog_title = $filtered_results['blog_title'];
 306      $errors = $filtered_results['errors'];
 307  
 308      if ( empty($blogname) )
 309          $blogname = $user_name;
 310      ?>
 311      <form id="setupform" method="post" action="wp-signup.php">
 312          <input type="hidden" name="stage" value="validate-blog-signup" />
 313          <input type="hidden" name="user_name" value="<?php echo $user_name ?>" />
 314          <input type="hidden" name="user_email" value="<?php echo $user_email ?>" />
 315          <?php do_action( "signup_hidden_fields" ); ?>
 316          <?php show_blog_form($blogname, $blog_title, $errors); ?>
 317          <p>
 318              <input id="submit" 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>
 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">' . 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>';
 379  
 380  $newblogname = isset($_GET['new']) ? strtolower(preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'])) : null;
 381  
 382  $current_user = wp_get_current_user();
 383  if( $active_signup == "none" ) {
 384      _e( "Registration has been disabled." );
 385  } elseif( $active_signup == 'blog' && !is_user_logged_in() ){
 386      if( is_ssl() ) {
 387          $proto = 'https://';
 388      } else {
 389          $proto = 'http://';
 390      }
 391      $login_url = site_url( 'wp-login.php?redirect_to=' . urlencode($proto . $_SERVER['HTTP_HOST'] . '/wp-signup.php' ));
 392      echo sprintf( __( "You must first <a href=\"%s\">login</a>, and then you can create a new blog."), $login_url );
 393  } else {
 394      switch ($_POST['stage']) {
 395          case 'validate-user-signup' :
 396              if( $active_signup == 'all' || $_POST[ 'signup_for' ] == 'blog' && $active_signup == 'blog' || $_POST[ 'signup_for' ] == 'user' && $active_signup == 'user' )
 397                  validate_user_signup();
 398              else
 399                  _e( "User registration has been disabled." );
 400          break;
 401          case 'validate-blog-signup':
 402              if( $active_signup == 'all' || $active_signup == 'blog' )
 403                  validate_blog_signup();
 404              else
 405                  _e( "Blog registration has been disabled." );
 406              break;
 407          case 'gimmeanotherblog':
 408              validate_another_blog_signup();
 409              break;
 410          default :
 411              $user_email = $_POST[ 'user_email' ];
 412              do_action( "preprocess_signup_form" ); // populate the form from invites, elsewhere?

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


Generated: Thu Mar 5 12:05:07 2009 Cross-referenced by PHPXref 0.7