[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/ -> wp-signup.php (source)

   1  <?php
   2  /**
   3   * WordPress Signup Page
   4   *
   5   * Handles the user registration and site creation process for multisite installations.
   6   *
   7   * @package WordPress
   8   */
   9  
  10  /** Sets up the WordPress Environment. */
  11  require  __DIR__ . '/wp-load.php';
  12  
  13  add_filter( 'wp_robots', 'wp_robots_no_robots' );
  14  
  15  require  __DIR__ . '/wp-blog-header.php';
  16  
  17  nocache_headers();
  18  
  19  if ( is_array( get_site_option( 'illegal_names' ) ) && isset( $_GET['new'] ) && in_array( $_GET['new'], get_site_option( 'illegal_names' ), true ) ) {
  20      wp_redirect( network_home_url() );
  21      die();
  22  }
  23  
  24  /**
  25   * Prints signup_header via wp_head.
  26   *
  27   * @since MU (3.0.0)
  28   */
  29  function do_signup_header() {
  30      /**
  31       * Fires within the head section of the site sign-up screen.
  32       *
  33       * @since 3.0.0
  34       */
  35      do_action( 'signup_header' );
  36  }
  37  add_action( 'wp_head', 'do_signup_header' );
  38  
  39  if ( ! is_multisite() ) {
  40      wp_redirect( wp_registration_url() );
  41      die();
  42  }
  43  
  44  if ( ! is_main_site() ) {
  45      wp_redirect( network_site_url( 'wp-signup.php' ) );
  46      die();
  47  }
  48  
  49  /**
  50   * @global WP_Query $wp_query WordPress Query object.
  51   */
  52  global $wp_query;
  53  
  54  // Fix for page title.
  55  $wp_query->is_404 = false;
  56  
  57  /**
  58   * Fires before the Site Sign-up page is loaded.
  59   *
  60   * @since 4.4.0
  61   */
  62  do_action( 'before_signup_header' );
  63  
  64  /**
  65   * Prints styles for front-end Multisite Sign-up pages.
  66   *
  67   * @since MU (3.0.0)
  68   */
  69  function wpmu_signup_stylesheet() {
  70      ?>
  71      <style>
  72          .mu_register { width: 90%; margin: 0 auto; text-align: start; padding: 24px; box-sizing: border-box; }
  73          .mu_register p { font-size: 18px; }
  74          .mu_register form { margin: 24px 0; }
  75          .mu_register fieldset,
  76              .mu_register legend { margin: 0; padding: 0; border: none; }
  77          .mu_register .error { padding: 10px; color: #333; background: #ffebe8; border: 1px solid #c00; }
  78          .mu_register input[type="submit"],
  79              .mu_register #blog_title,
  80              .mu_register #user_email,
  81              .mu_register #blogname,
  82              .mu_register #user_name { width: 100%; font-size: 24px; margin: 5px 0; box-sizing: border-box; }
  83          .mu_register input[type="email"],
  84              .mu_register #user_name { direction: ltr; }
  85          .mu_register #site-language { display: block; }
  86          .mu_register label[for="site-language"] { display: inline-flex; align-items: center; }
  87          .mu_register label[for="site-language"] .dashicons { margin-left: 0.5em; }
  88          .mu_register .prefix_address,
  89              .mu_register .suffix_address { font-size: 18px; display: inline-block; direction: ltr; }
  90          .mu_register label,
  91              .mu_register legend,
  92              .mu_register .label-heading { font-weight: 600; font-size: 15px; display: block; margin: 10px 0; }
  93          .mu_register legend + p,
  94              .mu_register input + p { margin-top: 0; }
  95          .mu_register label.checkbox { display: inline; }
  96          .mu_register .mu_alert { font-weight: 600; padding: 10px; color: #333; background: #ffffe0; border: 1px solid #e6db55; }
  97          .mu_register .mu_alert a { color: inherit; text-decoration: underline; }
  98          .mu_register .signup-options .wp-signup-radio-button { display: block; }
  99          .mu_register .privacy-intro .wp-signup-radio-button { margin-right: 0.5em; }
 100          .rtl .mu_register .wp-signup-blogname { direction: ltr; text-align: right; }
 101          .rtl .mu_register label[for="site-language"] .dashicons { margin-right: 0.5em; margin-left: 0; }
 102      </style>
 103      <?php
 104  }
 105  add_action( 'wp_head', 'wpmu_signup_stylesheet' );
 106  
 107  get_header( 'wp-signup' );
 108  
 109  /**
 110   * Fires before the site Sign-up form.
 111   *
 112   * @since 3.0.0
 113   */
 114  do_action( 'before_signup_form' );
 115  ?>
 116  <div id="signup-content" class="widecolumn">
 117  <div class="mu_register wp-signup-container" role="main">
 118  <?php
 119  /**
 120   * Generates and displays the Sign-up and Create Site forms.
 121   *
 122   * @since MU (3.0.0)
 123   *
 124   * @param string          $blogname   The new site name.
 125   * @param string          $blog_title The new site title.
 126   * @param WP_Error|string $errors     A WP_Error object containing existing errors. Defaults to empty string.
 127   */
 128  function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
 129      if ( ! is_wp_error( $errors ) ) {
 130          $errors = new WP_Error();
 131      }
 132  
 133      $current_network = get_network();
 134      // Site name.
 135      if ( ! is_subdomain_install() ) {
 136          echo '<label for="blogname">' . __( 'Site Name (subdirectory only)' ) . '</label>';
 137      } else {
 138          echo '<label for="blogname">' . __( 'Site Domain (subdomain only)' ) . '</label>';
 139      }
 140  
 141      $errmsg_blogname      = $errors->get_error_message( 'blogname' );
 142      $errmsg_blogname_aria = '';
 143      if ( $errmsg_blogname ) {
 144          $errmsg_blogname_aria = 'wp-signup-blogname-error ';
 145          echo '<p class="error" id="wp-signup-blogname-error">' . $errmsg_blogname . '</p>';
 146      }
 147  
 148      if ( ! is_subdomain_install() ) {
 149          echo '<div class="wp-signup-blogname"><span class="prefix_address" id="prefix-address">' . $current_network->domain . $current_network->path . '</span><input name="blogname" type="text" id="blogname" value="' . esc_attr( $blogname ) . '" maxlength="60" autocomplete="off" required="required" aria-describedby="' . $errmsg_blogname_aria . 'prefix-address" /></div>';
 150      } else {
 151          $site_domain = preg_replace( '|^www\.|', '', $current_network->domain );
 152          echo '<div class="wp-signup-blogname"><input name="blogname" type="text" id="blogname" value="' . esc_attr( $blogname ) . '" maxlength="60" autocomplete="off" required="required" aria-describedby="' . $errmsg_blogname_aria . 'suffix-address" /><span class="suffix_address" id="suffix-address">.' . esc_html( $site_domain ) . '</span></div>';
 153      }
 154  
 155      if ( ! is_user_logged_in() ) {
 156          if ( ! is_subdomain_install() ) {
 157              $site = $current_network->domain . $current_network->path . __( 'sitename' );
 158          } else {
 159              $site = __( 'domain' ) . '.' . $site_domain . $current_network->path;
 160          }
 161  
 162          printf(
 163              '<p>(<strong>%s</strong>) %s</p>',
 164              /* translators: %s: Site address. */
 165              sprintf( __( 'Your address will be %s.' ), $site ),
 166              __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!' )
 167          );
 168      }
 169  
 170      // Site Title.
 171      ?>
 172      <label for="blog_title"><?php _e( 'Site Title' ); ?></label>
 173      <?php
 174      $errmsg_blog_title      = $errors->get_error_message( 'blog_title' );
 175      $errmsg_blog_title_aria = '';
 176      if ( $errmsg_blog_title ) {
 177          $errmsg_blog_title_aria = ' aria-describedby="wp-signup-blog-title-error"';
 178          echo '<p class="error" id="wp-signup-blog-title-error">' . $errmsg_blog_title . '</p>';
 179      }
 180      echo '<input name="blog_title" type="text" id="blog_title" value="' . esc_attr( $blog_title ) . '" required="required" autocomplete="off"' . $errmsg_blog_title_aria . ' />';
 181      ?>
 182  
 183      <?php
 184      // Site Language.
 185      $languages = signup_get_available_languages();
 186  
 187      if ( ! empty( $languages ) ) :
 188          ?>
 189          <p>
 190              <label for="site-language"><?php _e( 'Site Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span></label>
 191              <?php
 192              // Network default.
 193              $lang = get_site_option( 'WPLANG' );
 194  
 195              if ( isset( $_POST['WPLANG'] ) ) {
 196                  $lang = $_POST['WPLANG'];
 197              }
 198  
 199              // Use US English if the default isn't available.
 200              if ( ! in_array( $lang, $languages, true ) ) {
 201                  $lang = '';
 202              }
 203  
 204              wp_dropdown_languages(
 205                  array(
 206                      'name'                        => 'WPLANG',
 207                      'id'                          => 'site-language',
 208                      'selected'                    => $lang,
 209                      'languages'                   => $languages,
 210                      'show_available_translations' => false,
 211                  )
 212              );
 213              ?>
 214          </p>
 215          <?php
 216          endif; // Languages.
 217  
 218          $blog_public_on_checked  = '';
 219          $blog_public_off_checked = '';
 220      if ( isset( $_POST['blog_public'] ) && '0' === $_POST['blog_public'] ) {
 221          $blog_public_off_checked = 'checked="checked"';
 222      } else {
 223          $blog_public_on_checked = 'checked="checked"';
 224      }
 225      ?>
 226  
 227      <div id="privacy">
 228          <fieldset class="privacy-intro">
 229              <legend>
 230                  <span class="label-heading"><?php _e( 'Privacy:' ); ?></span>
 231                  <?php _e( 'Allow search engines to index this site.' ); ?>
 232              </legend>
 233              <p class="wp-signup-radio-buttons">
 234                  <span class="wp-signup-radio-button">
 235                      <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php echo $blog_public_on_checked; ?> />
 236                      <label class="checkbox" for="blog_public_on"><?php _e( 'Yes' ); ?></label>
 237                  </span>
 238                  <span class="wp-signup-radio-button">
 239                      <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php echo $blog_public_off_checked; ?> />
 240                      <label class="checkbox" for="blog_public_off"><?php _e( 'No' ); ?></label>
 241                  </span>
 242              </p>
 243          </fieldset>
 244      </div>
 245  
 246      <?php
 247      /**
 248       * Fires after the site sign-up form.
 249       *
 250       * @since 3.0.0
 251       *
 252       * @param WP_Error $errors A WP_Error object possibly containing 'blogname' or 'blog_title' errors.
 253       */
 254      do_action( 'signup_blogform', $errors );
 255  }
 256  
 257  /**
 258   * Validates the new site sign-up.
 259   *
 260   * @since MU (3.0.0)
 261   *
 262   * @return array Contains the new site data and error messages.
 263   *               See wpmu_validate_blog_signup() for details.
 264   */
 265  function validate_blog_form() {
 266      $user = '';
 267      if ( is_user_logged_in() ) {
 268          $user = wp_get_current_user();
 269      }
 270  
 271      return wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'], $user );
 272  }
 273  
 274  /**
 275   * Displays the fields for the new user account registration form.
 276   *
 277   * @since MU (3.0.0)
 278   *
 279   * @param string          $user_name  The entered username.
 280   * @param string          $user_email The entered email address.
 281   * @param WP_Error|string $errors     A WP_Error object containing existing errors. Defaults to empty string.
 282   */
 283  function show_user_form( $user_name = '', $user_email = '', $errors = '' ) {
 284      if ( ! is_wp_error( $errors ) ) {
 285          $errors = new WP_Error();
 286      }
 287  
 288      // Username.
 289      echo '<label for="user_name">' . __( 'Username' ) . '</label>';
 290      $errmsg_username      = $errors->get_error_message( 'user_name' );
 291      $errmsg_username_aria = '';
 292      if ( $errmsg_username ) {
 293          $errmsg_username_aria = 'wp-signup-username-error ';
 294          echo '<p class="error" id="wp-signup-username-error">' . $errmsg_username . '</p>';
 295      }
 296      ?>
 297      <input name="user_name" type="text" id="user_name" value="<?php echo esc_attr( $user_name ); ?>" autocapitalize="none" autocorrect="off" maxlength="60" autocomplete="username" required="required" aria-describedby="<?php echo $errmsg_username_aria; ?>wp-signup-username-description" />
 298      <p id="wp-signup-username-description"><?php _e( '(Must be at least 4 characters, lowercase letters and numbers only.)' ); ?></p>
 299  
 300      <?php
 301      // Email address.
 302      echo '<label for="user_email">' . __( 'Email&nbsp;Address' ) . '</label>';
 303      $errmsg_email      = $errors->get_error_message( 'user_email' );
 304      $errmsg_email_aria = '';
 305      if ( $errmsg_email ) {
 306          $errmsg_email_aria = 'wp-signup-email-error ';
 307          echo '<p class="error" id="wp-signup-email-error">' . $errmsg_email . '</p>';
 308      }
 309      ?>
 310      <input name="user_email" type="email" id="user_email" value="<?php echo esc_attr( $user_email ); ?>" maxlength="200" autocomplete="email" required="required" aria-describedby="<?php echo $errmsg_email_aria; ?>wp-signup-email-description" />
 311      <p id="wp-signup-email-description"><?php _e( 'Your registration email is sent to this address. (Double-check your email address before continuing.)' ); ?></p>
 312  
 313      <?php
 314      // Extra fields.
 315      $errmsg_generic = $errors->get_error_message( 'generic' );
 316      if ( $errmsg_generic ) {
 317          echo '<p class="error" id="wp-signup-generic-error">' . $errmsg_generic . '</p>';
 318      }
 319      /**
 320       * Fires at the end of the new user account registration form.
 321       *
 322       * @since 3.0.0
 323       *
 324       * @param WP_Error $errors A WP_Error object containing 'user_name' or 'user_email' errors.
 325       */
 326      do_action( 'signup_extra_fields', $errors );
 327  }
 328  
 329  /**
 330   * Validates user sign-up name and email.
 331   *
 332   * @since MU (3.0.0)
 333   *
 334   * @return array Contains username, email, and error messages.
 335   *               See wpmu_validate_user_signup() for details.
 336   */
 337  function validate_user_form() {
 338      return wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
 339  }
 340  
 341  /**
 342   * Shows a form for returning users to sign up for another site.
 343   *
 344   * @since MU (3.0.0)
 345   *
 346   * @param string          $blogname   The new site name
 347   * @param string          $blog_title The new site title.
 348   * @param WP_Error|string $errors     A WP_Error object containing existing errors. Defaults to empty string.
 349   */
 350  function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) {
 351      $current_user = wp_get_current_user();
 352  
 353      if ( ! is_wp_error( $errors ) ) {
 354          $errors = new WP_Error();
 355      }
 356  
 357      $signup_defaults = array(
 358          'blogname'   => $blogname,
 359          'blog_title' => $blog_title,
 360          'errors'     => $errors,
 361      );
 362  
 363      /**
 364       * Filters the default site sign-up variables.
 365       *
 366       * @since 3.0.0
 367       *
 368       * @param array $signup_defaults {
 369       *     An array of default site sign-up variables.
 370       *
 371       *     @type string   $blogname   The site blogname.
 372       *     @type string   $blog_title The site title.
 373       *     @type WP_Error $errors     A WP_Error object possibly containing 'blogname' or 'blog_title' errors.
 374       * }
 375       */
 376      $filtered_results = apply_filters( 'signup_another_blog_init', $signup_defaults );
 377  
 378      $blogname   = $filtered_results['blogname'];
 379      $blog_title = $filtered_results['blog_title'];
 380      $errors     = $filtered_results['errors'];
 381  
 382      /* translators: %s: Network title. */
 383      echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), get_network()->site_name ) . '</h2>';
 384  
 385      if ( $errors->has_errors() ) {
 386          echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
 387      }
 388      ?>
 389      <p>
 390          <?php
 391          printf(
 392              /* translators: %s: Current user's display name. */
 393              __( '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!' ),
 394              $current_user->display_name
 395          );
 396          ?>
 397      </p>
 398  
 399      <?php
 400      $blogs = get_blogs_of_user( $current_user->ID );
 401      if ( ! empty( $blogs ) ) {
 402          ?>
 403  
 404              <p><?php _e( 'Sites you are already a member of:' ); ?></p>
 405              <ul>
 406                  <?php
 407                  foreach ( $blogs as $blog ) {
 408                      $home_url = get_home_url( $blog->userblog_id );
 409                      echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
 410                  }
 411                  ?>
 412              </ul>
 413      <?php } ?>
 414  
 415      <p><?php _e( 'If you are not going to use a great site domain, leave it for a new user. Now have at it!' ); ?></p>
 416      <form id="setupform" method="post" action="wp-signup.php">
 417          <input type="hidden" name="stage" value="gimmeanotherblog" />
 418          <?php
 419          /**
 420           * Fires when hidden sign-up form fields output when creating another site or user.
 421           *
 422           * @since MU (3.0.0)
 423           *
 424           * @param string $context A string describing the steps of the sign-up process. The value can be
 425           *                        'create-another-site', 'validate-user', or 'validate-site'.
 426           */
 427          do_action( 'signup_hidden_fields', 'create-another-site' );
 428          ?>
 429          <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
 430          <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ); ?>" /></p>
 431      </form>
 432      <?php
 433  }
 434  
 435  /**
 436   * Validates a new site sign-up for an existing user.
 437   *
 438   * @since MU (3.0.0)
 439   *
 440   * @global string   $blogname   The new site's subdomain or directory name.
 441   * @global string   $blog_title The new site's title.
 442   * @global WP_Error $errors     Existing errors in the global scope.
 443   * @global string   $domain     The new site's domain.
 444   * @global string   $path       The new site's path.
 445   *
 446   * @return null|bool True if site signup was validated, false on error.
 447   *                   The function halts all execution if the user is not logged in.
 448   */
 449  function validate_another_blog_signup() {
 450      global $blogname, $blog_title, $errors, $domain, $path;
 451      $current_user = wp_get_current_user();
 452      if ( ! is_user_logged_in() ) {
 453          die();
 454      }
 455  
 456      $result = validate_blog_form();
 457  
 458      // Extracted values set/overwrite globals.
 459      $domain     = $result['domain'];
 460      $path       = $result['path'];
 461      $blogname   = $result['blogname'];
 462      $blog_title = $result['blog_title'];
 463      $errors     = $result['errors'];
 464  
 465      if ( $errors->has_errors() ) {
 466          signup_another_blog( $blogname, $blog_title, $errors );
 467          return false;
 468      }
 469  
 470      $public = (int) $_POST['blog_public'];
 471  
 472      $blog_meta_defaults = array(
 473          'lang_id' => 1,
 474          'public'  => $public,
 475      );
 476  
 477      // Handle the language setting for the new site.
 478      if ( ! empty( $_POST['WPLANG'] ) ) {
 479  
 480          $languages = signup_get_available_languages();
 481  
 482          if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
 483              $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
 484  
 485              if ( $language ) {
 486                  $blog_meta_defaults['WPLANG'] = $language;
 487              }
 488          }
 489      }
 490  
 491      /**
 492       * Filters the new site meta variables.
 493       *
 494       * Use the {@see 'add_signup_meta'} filter instead.
 495       *
 496       * @since MU (3.0.0)
 497       * @deprecated 3.0.0 Use the {@see 'add_signup_meta'} filter instead.
 498       *
 499       * @param array $blog_meta_defaults An array of default blog meta variables.
 500       */
 501      $meta_defaults = apply_filters_deprecated( 'signup_create_blog_meta', array( $blog_meta_defaults ), '3.0.0', 'add_signup_meta' );
 502  
 503      /**
 504       * Filters the new default site meta variables.
 505       *
 506       * @since 3.0.0
 507       *
 508       * @param array $meta {
 509       *     An array of default site meta variables.
 510       *
 511       *     @type int $lang_id     The language ID.
 512       *     @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
 513       * }
 514       */
 515      $meta = apply_filters( 'add_signup_meta', $meta_defaults );
 516  
 517      $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, get_current_network_id() );
 518  
 519      if ( is_wp_error( $blog_id ) ) {
 520          return false;
 521      }
 522  
 523      confirm_another_blog_signup( $domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta, $blog_id );
 524      return true;
 525  }
 526  
 527  /**
 528   * Shows a message confirming that the new site has been created.
 529   *
 530   * @since MU (3.0.0)
 531   * @since 4.4.0 Added the `$blog_id` parameter.
 532   *
 533   * @param string $domain     The domain URL.
 534   * @param string $path       The site root path.
 535   * @param string $blog_title The site title.
 536   * @param string $user_name  The username.
 537   * @param string $user_email The user's email address.
 538   * @param array  $meta       Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
 539   * @param int    $blog_id    The site ID.
 540   */
 541  function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 ) {
 542  
 543      if ( $blog_id ) {
 544          switch_to_blog( $blog_id );
 545          $home_url  = home_url( '/' );
 546          $login_url = wp_login_url();
 547          restore_current_blog();
 548      } else {
 549          $home_url  = 'http://' . $domain . $path;
 550          $login_url = 'http://' . $domain . $path . 'wp-login.php';
 551      }
 552  
 553      $site = sprintf(
 554          '<a href="%1$s">%2$s</a>',
 555          esc_url( $home_url ),
 556          $blog_title
 557      );
 558  
 559      ?>
 560      <h2>
 561      <?php
 562          /* translators: %s: Site title. */
 563          printf( __( 'The site %s is yours.' ), $site );
 564      ?>
 565      </h2>
 566      <p>
 567          <?php
 568          printf(
 569              /* translators: 1: Link to new site, 2: Login URL, 3: Username. */
 570              __( '%1$s is your new site. <a href="%2$s">Log in</a> as &#8220;%3$s&#8221; using your existing password.' ),
 571              sprintf(
 572                  '<a href="%s">%s</a>',
 573                  esc_url( $home_url ),
 574                  untrailingslashit( $domain . $path )
 575              ),
 576              esc_url( $login_url ),
 577              $user_name
 578          );
 579          ?>
 580      </p>
 581      <?php
 582      /**
 583       * Fires when the site or user sign-up process is complete.
 584       *
 585       * @since 3.0.0
 586       */
 587      do_action( 'signup_finished' );
 588  }
 589  
 590  /**
 591   * Shows a form for a visitor to sign up for a new user account.
 592   *
 593   * @since MU (3.0.0)
 594   *
 595   * @global string $active_signup String that returns registration type. The value can be
 596   *                               'all', 'none', 'blog', or 'user'.
 597   *
 598   * @param string          $user_name  The username.
 599   * @param string          $user_email The user's email.
 600   * @param WP_Error|string $errors     A WP_Error object containing existing errors. Defaults to empty string.
 601   */
 602  function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
 603      global $active_signup;
 604  
 605      if ( ! is_wp_error( $errors ) ) {
 606          $errors = new WP_Error();
 607      }
 608  
 609      $signup_for = isset( $_POST['signup_for'] ) ? esc_html( $_POST['signup_for'] ) : 'blog';
 610  
 611      $signup_user_defaults = array(
 612          'user_name'  => $user_name,
 613          'user_email' => $user_email,
 614          'errors'     => $errors,
 615      );
 616  
 617      /**
 618       * Filters the default user variables used on the user sign-up form.
 619       *
 620       * @since 3.0.0
 621       *
 622       * @param array $signup_user_defaults {
 623       *     An array of default user variables.
 624       *
 625       *     @type string   $user_name  The user username.
 626       *     @type string   $user_email The user email address.
 627       *     @type WP_Error $errors     A WP_Error object with possible errors relevant to the sign-up user.
 628       * }
 629       */
 630      $filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
 631      $user_name        = $filtered_results['user_name'];
 632      $user_email       = $filtered_results['user_email'];
 633      $errors           = $filtered_results['errors'];
 634  
 635      ?>
 636  
 637      <h2>
 638      <?php
 639          /* translators: %s: Name of the network. */
 640          printf( __( 'Get your own %s account in seconds' ), get_network()->site_name );
 641      ?>
 642      </h2>
 643      <form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
 644          <input type="hidden" name="stage" value="validate-user-signup" />
 645          <?php
 646          /** This action is documented in wp-signup.php */
 647          do_action( 'signup_hidden_fields', 'validate-user' );
 648          ?>
 649          <?php show_user_form( $user_name, $user_email, $errors ); ?>
 650  
 651          <?php if ( 'blog' === $active_signup ) : ?>
 652              <input id="signupblog" type="hidden" name="signup_for" value="blog" />
 653          <?php elseif ( 'user' === $active_signup ) : ?>
 654              <input id="signupblog" type="hidden" name="signup_for" value="user" />
 655          <?php else : ?>
 656              <fieldset class="signup-options">
 657                  <legend><?php _e( 'Create a site or only a username:' ); ?></legend>
 658                  <p class="wp-signup-radio-buttons">
 659                      <span class="wp-signup-radio-button">
 660                          <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
 661                          <label class="checkbox" for="signupblog"><?php _e( 'Gimme a site!' ); ?></label>
 662                      </span>
 663                      <span class="wp-signup-radio-button">
 664                          <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
 665                          <label class="checkbox" for="signupuser"><?php _e( 'Just a username, please.' ); ?></label>
 666                      </span>
 667                  </p>
 668              </fieldset>
 669          <?php endif; ?>
 670  
 671          <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Next' ); ?>" /></p>
 672      </form>
 673      <?php
 674  }
 675  
 676  /**
 677   * Validates the new user sign-up.
 678   *
 679   * @since MU (3.0.0)
 680   *
 681   * @return bool True if new user sign-up was validated, false on error.
 682   */
 683  function validate_user_signup() {
 684      $result     = validate_user_form();
 685      $user_name  = $result['user_name'];
 686      $user_email = $result['user_email'];
 687      $errors     = $result['errors'];
 688  
 689      if ( $errors->has_errors() ) {
 690          signup_user( $user_name, $user_email, $errors );
 691          return false;
 692      }
 693  
 694      if ( 'blog' === $_POST['signup_for'] ) {
 695          signup_blog( $user_name, $user_email );
 696          return false;
 697      }
 698  
 699      /** This filter is documented in wp-signup.php */
 700      wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
 701  
 702      confirm_user_signup( $user_name, $user_email );
 703      return true;
 704  }
 705  
 706  /**
 707   * Shows a message confirming that the new user has been registered and is awaiting activation.
 708   *
 709   * @since MU (3.0.0)
 710   *
 711   * @param string $user_name  The username.
 712   * @param string $user_email The user's email address.
 713   */
 714  function confirm_user_signup( $user_name, $user_email ) {
 715      ?>
 716      <h2>
 717      <?php
 718      /* translators: %s: Username. */
 719      printf( __( '%s is your new username' ), $user_name )
 720      ?>
 721      </h2>
 722      <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ); ?></p>
 723      <p>
 724      <?php
 725      /* translators: %s: The user email address. */
 726      printf( __( 'Check your inbox at %s and click on the given link.' ), '<strong>' . $user_email . '</strong>' );
 727      ?>
 728      </p>
 729      <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
 730      <?php
 731      /** This action is documented in wp-signup.php */
 732      do_action( 'signup_finished' );
 733  }
 734  
 735  /**
 736   * Shows a form for a user or visitor to sign up for a new site.
 737   *
 738   * @since MU (3.0.0)
 739   *
 740   * @param string          $user_name  The username.
 741   * @param string          $user_email The user's email address.
 742   * @param string          $blogname   The site name.
 743   * @param string          $blog_title The site title.
 744   * @param WP_Error|string $errors     A WP_Error object containing existing errors. Defaults to empty string.
 745   */
 746  function signup_blog( $user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '' ) {
 747      if ( ! is_wp_error( $errors ) ) {
 748          $errors = new WP_Error();
 749      }
 750  
 751      $signup_blog_defaults = array(
 752          'user_name'  => $user_name,
 753          'user_email' => $user_email,
 754          'blogname'   => $blogname,
 755          'blog_title' => $blog_title,
 756          'errors'     => $errors,
 757      );
 758  
 759      /**
 760       * Filters the default site creation variables for the site sign-up form.
 761       *
 762       * @since 3.0.0
 763       *
 764       * @param array $signup_blog_defaults {
 765       *     An array of default site creation variables.
 766       *
 767       *     @type string   $user_name  The user username.
 768       *     @type string   $user_email The user email address.
 769       *     @type string   $blogname   The blogname.
 770       *     @type string   $blog_title The title of the site.
 771       *     @type WP_Error $errors     A WP_Error object with possible errors relevant to new site creation variables.
 772       * }
 773       */
 774      $filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults );
 775  
 776      $user_name  = $filtered_results['user_name'];
 777      $user_email = $filtered_results['user_email'];
 778      $blogname   = $filtered_results['blogname'];
 779      $blog_title = $filtered_results['blog_title'];
 780      $errors     = $filtered_results['errors'];
 781  
 782      if ( empty( $blogname ) ) {
 783          $blogname = $user_name;
 784      }
 785      ?>
 786      <form id="setupform" method="post" action="wp-signup.php">
 787          <input type="hidden" name="stage" value="validate-blog-signup" />
 788          <input type="hidden" name="user_name" value="<?php echo esc_attr( $user_name ); ?>" />
 789          <input type="hidden" name="user_email" value="<?php echo esc_attr( $user_email ); ?>" />
 790          <?php
 791          /** This action is documented in wp-signup.php */
 792          do_action( 'signup_hidden_fields', 'validate-site' );
 793          ?>
 794          <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
 795          <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Sign up' ); ?>" /></p>
 796      </form>
 797      <?php
 798  }
 799  
 800  /**
 801   * Validates new site signup.
 802   *
 803   * @since MU (3.0.0)
 804   *
 805   * @return bool True if the site sign-up was validated, false on error.
 806   */
 807  function validate_blog_signup() {
 808      // Re-validate user info.
 809      $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
 810      $user_name   = $user_result['user_name'];
 811      $user_email  = $user_result['user_email'];
 812      $user_errors = $user_result['errors'];
 813  
 814      if ( $user_errors->has_errors() ) {
 815          signup_user( $user_name, $user_email, $user_errors );
 816          return false;
 817      }
 818  
 819      $result     = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] );
 820      $domain     = $result['domain'];
 821      $path       = $result['path'];
 822      $blogname   = $result['blogname'];
 823      $blog_title = $result['blog_title'];
 824      $errors     = $result['errors'];
 825  
 826      if ( $errors->has_errors() ) {
 827          signup_blog( $user_name, $user_email, $blogname, $blog_title, $errors );
 828          return false;
 829      }
 830  
 831      $public      = (int) $_POST['blog_public'];
 832      $signup_meta = array(
 833          'lang_id' => 1,
 834          'public'  => $public,
 835      );
 836  
 837      // Handle the language setting for the new site.
 838      if ( ! empty( $_POST['WPLANG'] ) ) {
 839  
 840          $languages = signup_get_available_languages();
 841  
 842          if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
 843              $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
 844  
 845              if ( $language ) {
 846                  $signup_meta['WPLANG'] = $language;
 847              }
 848          }
 849      }
 850  
 851      /** This filter is documented in wp-signup.php */
 852      $meta = apply_filters( 'add_signup_meta', $signup_meta );
 853  
 854      wpmu_signup_blog( $domain, $path, $blog_title, $user_name, $user_email, $meta );
 855      confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email, $meta );
 856      return true;
 857  }
 858  
 859  /**
 860   * Shows a message confirming that the new site has been registered and is awaiting activation.
 861   *
 862   * @since MU (3.0.0)
 863   *
 864   * @param string $domain     The domain or subdomain of the site.
 865   * @param string $path       The path of the site.
 866   * @param string $blog_title The title of the new site.
 867   * @param string $user_name  The user's username.
 868   * @param string $user_email The user's email address.
 869   * @param array  $meta       Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
 870   */
 871  function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
 872      ?>
 873      <h2>
 874      <?php
 875      /* translators: %s: Site address. */
 876      printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='//{$domain}{$path}'>{$blog_title}</a>" )
 877      ?>
 878      </h2>
 879  
 880      <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ); ?></p>
 881      <p>
 882      <?php
 883      /* translators: %s: The user email address. */
 884      printf( __( 'Check your inbox at %s and click on the given link.' ), '<strong>' . $user_email . '</strong>' );
 885      ?>
 886      </p>
 887      <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
 888      <h2><?php _e( 'Still waiting for your email?' ); ?></h2>
 889      <p><?php _e( 'If you have not received your email yet, there are a number of things you can do:' ); ?></p>
 890      <ul id="noemail-tips">
 891          <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>
 892          <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ); ?></p></li>
 893          <li>
 894          <?php
 895              /* translators: %s: Email address. */
 896              printf( __( 'Have you entered your email correctly? You have entered %s, if it&#8217;s incorrect, you will not receive your email.' ), $user_email );
 897          ?>
 898          </li>
 899      </ul>
 900      <?php
 901      /** This action is documented in wp-signup.php */
 902      do_action( 'signup_finished' );
 903  }
 904  
 905  /**
 906   * Retrieves languages available during the site/user sign-up process.
 907   *
 908   * @since 4.4.0
 909   *
 910   * @see get_available_languages()
 911   *
 912   * @return string[] Array of available language codes. Language codes are formed by
 913   *                  stripping the .mo extension from the language file names.
 914   */
 915  function signup_get_available_languages() {
 916      /**
 917       * Filters the list of available languages for front-end site sign-ups.
 918       *
 919       * Passing an empty array to this hook will disable output of the setting on the
 920       * sign-up form, and the default language will be used when creating the site.
 921       *
 922       * Languages not already installed will be stripped.
 923       *
 924       * @since 4.4.0
 925       *
 926       * @param string[] $languages Array of available language codes. Language codes are formed by
 927       *                            stripping the .mo extension from the language file names.
 928       */
 929      $languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() );
 930  
 931      /*
 932       * Strip any non-installed languages and return.
 933       *
 934       * Re-call get_available_languages() here in case a language pack was installed
 935       * in a callback hooked to the 'signup_get_available_languages' filter before this point.
 936       */
 937      return array_intersect_assoc( $languages, get_available_languages() );
 938  }
 939  
 940  // Main.
 941  $active_signup = get_site_option( 'registration', 'none' );
 942  
 943  /**
 944   * Filters the type of site sign-up.
 945   *
 946   * @since 3.0.0
 947   *
 948   * @param string $active_signup String that returns registration type. The value can be
 949   *                              'all', 'none', 'blog', or 'user'.
 950   */
 951  $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
 952  
 953  if ( current_user_can( 'manage_network' ) ) {
 954      echo '<div class="mu_alert">';
 955      _e( 'Greetings Network Administrator!' );
 956      echo ' ';
 957  
 958      switch ( $active_signup ) {
 959          case 'none':
 960              _e( 'The network currently disallows registrations.' );
 961              break;
 962          case 'blog':
 963              _e( 'The network currently allows site registrations.' );
 964              break;
 965          case 'user':
 966              _e( 'The network currently allows user registrations.' );
 967              break;
 968          default:
 969              _e( 'The network currently allows both site and user registrations.' );
 970              break;
 971      }
 972  
 973      echo ' ';
 974  
 975      /* translators: %s: URL to Network Settings screen. */
 976      printf( __( 'To change or disable registration go to your <a href="%s">Options page</a>.' ), esc_url( network_admin_url( 'settings.php' ) ) );
 977      echo '</div>';
 978  }
 979  
 980  $newblogname = isset( $_GET['new'] ) ? strtolower( preg_replace( '/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'] ) ) : null;
 981  
 982  $current_user = wp_get_current_user();
 983  if ( 'none' === $active_signup ) {
 984      _e( 'Registration has been disabled.' );
 985  } elseif ( 'blog' === $active_signup && ! is_user_logged_in() ) {
 986      $login_url = wp_login_url( network_site_url( 'wp-signup.php' ) );
 987      /* translators: %s: Login URL. */
 988      printf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
 989  } else {
 990      $stage = $_POST['stage'] ?? 'default';
 991      switch ( $stage ) {
 992          case 'validate-user-signup':
 993              if ( 'all' === $active_signup
 994                  || ( 'blog' === $_POST['signup_for'] && 'blog' === $active_signup )
 995                  || ( 'user' === $_POST['signup_for'] && 'user' === $active_signup )
 996              ) {
 997                  validate_user_signup();
 998              } else {
 999                  _e( 'User registration has been disabled.' );
1000              }
1001              break;
1002          case 'validate-blog-signup':
1003              if ( 'all' === $active_signup || 'blog' === $active_signup ) {
1004                  validate_blog_signup();
1005              } else {
1006                  _e( 'Site registration has been disabled.' );
1007              }
1008              break;
1009          case 'gimmeanotherblog':
1010              if ( 'all' === $active_signup || 'blog' === $active_signup ) {
1011                  validate_another_blog_signup();
1012              } else {
1013                  _e( 'Site registration has been disabled.' );
1014              }
1015              break;
1016          case 'default':
1017          default:
1018              $user_email = $_POST['user_email'] ?? '';
1019              /**
1020               * Fires when the site sign-up form is sent.
1021               *
1022               * @since 3.0.0
1023               */
1024              do_action( 'preprocess_signup_form' );
1025              if ( is_user_logged_in() && ( 'all' === $active_signup || 'blog' === $active_signup ) ) {
1026                  signup_another_blog( $newblogname );
1027              } elseif ( ! is_user_logged_in() && ( 'all' === $active_signup || 'user' === $active_signup ) ) {
1028                  signup_user( $newblogname, $user_email );
1029              } elseif ( ! is_user_logged_in() && ( 'blog' === $active_signup ) ) {
1030                  _e( 'Sorry, new registrations are not allowed at this time.' );
1031              } else {
1032                  _e( 'You are logged in already. No need to register again!' );
1033              }
1034  
1035              if ( $newblogname ) {
1036                  $newblog = get_blogaddress_by_name( $newblogname );
1037  
1038                  if ( 'blog' === $active_signup || 'all' === $active_signup ) {
1039                      printf(
1040                          /* translators: %s: Site address. */
1041                          '<p>' . __( 'The site you were looking for, %s, does not exist, but you can create it now!' ) . '</p>',
1042                          '<strong>' . $newblog . '</strong>'
1043                      );
1044                  } else {
1045                      printf(
1046                          /* translators: %s: Site address. */
1047                          '<p>' . __( 'The site you were looking for, %s, does not exist.' ) . '</p>',
1048                          '<strong>' . $newblog . '</strong>'
1049                      );
1050                  }
1051              }
1052              break;
1053      }
1054  }
1055  ?>
1056  </div>
1057  </div>
1058  <?php
1059  /**
1060   * Fires after the sign-up forms, before wp_footer.
1061   *
1062   * @since 3.0.0
1063   */
1064  do_action( 'after_signup_form' );
1065  ?>
1066  
1067  <?php
1068  get_footer( 'wp-signup' );


Generated : Fri Oct 9 08:20:33 2026 Cross-referenced by PHPXref