[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sun Sep 26 01:00:08 2021 Cross-referenced by PHPXref 0.7.1