ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

wp-signup.php (31693B)


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