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


Generated : Fri Jul 31 08:20:18 2026 Cross-referenced by PHPXref