[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/ -> wp-signup.php (source)

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


Generated : Wed Jun 19 08:20:01 2024 Cross-referenced by PHPXref