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


Generated: Tue Feb 19 01:00:05 2019 Cross-referenced by PHPXref 0.7.1