[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/ -> wp-signup.php (source)

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


Generated: Sat Dec 15 01:00:07 2018 Cross-referenced by PHPXref 0.7.1