home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-signup.php < prev    next >
Encoding:
PHP Script  |  2017-10-18  |  29.4 KB  |  923 lines

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