[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sat Dec 16 01:00:03 2017 Cross-referenced by PHPXref 0.7.1