wp/wp-signup.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    17  *
    17  *
    18  * @since MU
    18  * @since MU
    19  */
    19  */
    20 function do_signup_header() {
    20 function do_signup_header() {
    21 	/**
    21 	/**
    22 	 * Fires within the <head> section of the site sign-up screen.
    22 	 * Fires within the head section of the site sign-up screen.
    23 	 *
    23 	 *
    24 	 * @since 3.0.0
    24 	 * @since 3.0.0
    25 	 */
    25 	 */
    26 	do_action( 'signup_header' );
    26 	do_action( 'signup_header' );
    27 }
    27 }
    85  *
    85  *
    86  * @param string $blogname The new site name
    86  * @param string $blogname The new site name
    87  * @param string $blog_title The new site title
    87  * @param string $blog_title The new site title
    88  * @param array $errors
    88  * @param array $errors
    89  */
    89  */
    90 function show_blog_form($blogname = '', $blog_title = '', $errors = '') {
    90 function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
    91 	global $current_site;
    91 	$current_site = get_current_site();
    92 	// Blog name
    92 	// Blog name
    93 	if ( !is_subdomain_install() )
    93 	if ( !is_subdomain_install() )
    94 		echo '<label for="blogname">' . __('Site Name:') . '</label>';
    94 		echo '<label for="blogname">' . __('Site Name:') . '</label>';
    95 	else
    95 	else
    96 		echo '<label for="blogname">' . __('Site Domain:') . '</label>';
    96 		echo '<label for="blogname">' . __('Site Domain:') . '</label>';
   151 /**
   151 /**
   152  * Validate the new site signup
   152  * Validate the new site signup
   153  *
   153  *
   154  * @since MU
   154  * @since MU
   155  *
   155  *
   156  * @uses wp_get_current_user() to retrieve the current user
       
   157  * @uses wpmu_validate_blog_signup() to validate new site signup for the current user
       
   158  * @return array Contains the new site data and error messages.
   156  * @return array Contains the new site data and error messages.
   159  */
   157  */
   160 function validate_blog_form() {
   158 function validate_blog_form() {
   161 	$user = '';
   159 	$user = '';
   162 	if ( is_user_logged_in() )
   160 	if ( is_user_logged_in() )
   186 
   184 
   187 	<label for="user_email"><?php _e( 'Email&nbsp;Address:' ) ?></label>
   185 	<label for="user_email"><?php _e( 'Email&nbsp;Address:' ) ?></label>
   188 	<?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
   186 	<?php if ( $errmsg = $errors->get_error_message('user_email') ) { ?>
   189 		<p class="error"><?php echo $errmsg ?></p>
   187 		<p class="error"><?php echo $errmsg ?></p>
   190 	<?php } ?>
   188 	<?php } ?>
   191 	<input name="user_email" type="text" 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.)') ?>
   189 	<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.)') ?>
   192 	<?php
   190 	<?php
   193 	if ( $errmsg = $errors->get_error_message('generic') ) {
   191 	if ( $errmsg = $errors->get_error_message('generic') ) {
   194 		echo '<p class="error">' . $errmsg . '</p>';
   192 		echo '<p class="error">' . $errmsg . '</p>';
   195 	}
   193 	}
   196 	/**
   194 	/**
   206 /**
   204 /**
   207  * Validate user signup name and email
   205  * Validate user signup name and email
   208  *
   206  *
   209  * @since MU
   207  * @since MU
   210  *
   208  *
   211  * @uses wpmu_validate_user_signup() to retrieve an array of user data
       
   212  * @return array Contains username, email, and error messages.
   209  * @return array Contains username, email, and error messages.
   213  */
   210  */
   214 function validate_user_form() {
   211 function validate_user_form() {
   215 	return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
   212 	return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
   216 }
   213 }
   218 /**
   215 /**
   219  * Allow returning users to sign up for another site
   216  * Allow returning users to sign up for another site
   220  *
   217  *
   221  * @since MU
   218  * @since MU
   222  *
   219  *
   223  * @uses wp_get_current_user() to get the current user
       
   224  * @param string $blogname The new site name
   220  * @param string $blogname The new site name
   225  * @param string $blog_title The new blog title
   221  * @param string $blog_title The new blog title
   226  * @param array $errors
   222  * @param array $errors
   227  */
   223  */
   228 function signup_another_blog($blogname = '', $blog_title = '', $errors = '') {
   224 function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) {
   229 	global $current_site;
       
   230 	$current_user = wp_get_current_user();
   225 	$current_user = wp_get_current_user();
   231 
   226 
   232 	if ( ! is_wp_error($errors) ) {
   227 	if ( ! is_wp_error($errors) ) {
   233 		$errors = new WP_Error();
   228 		$errors = new WP_Error();
   234 	}
   229 	}
   256 
   251 
   257 	$blogname = $filtered_results['blogname'];
   252 	$blogname = $filtered_results['blogname'];
   258 	$blog_title = $filtered_results['blog_title'];
   253 	$blog_title = $filtered_results['blog_title'];
   259 	$errors = $filtered_results['errors'];
   254 	$errors = $filtered_results['errors'];
   260 
   255 
   261 	echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), $current_site->site_name ) . '</h2>';
   256 	echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), get_current_site()->site_name ) . '</h2>';
   262 
   257 
   263 	if ( $errors->get_error_code() ) {
   258 	if ( $errors->get_error_code() ) {
   264 		echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
   259 		echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
   265 	}
   260 	}
   266 	?>
   261 	?>
   302 /**
   297 /**
   303  * Validate a new blog signup
   298  * Validate a new blog signup
   304  *
   299  *
   305  * @since MU
   300  * @since MU
   306  *
   301  *
   307  * @uses wp_get_current_user() to retrieve the current user
   302  * @return null|boolean True if blog signup was validated, false if error.
   308  * @uses wpmu_create_blog() to add a new site
   303  *                      The function halts all execution if the user is not logged in.
   309  * @uses confirm_another_blog_signup() to confirm the user's new site signup
       
   310  * @return bool True if blog signup was validated, false if error
       
   311  */
   304  */
   312 function validate_another_blog_signup() {
   305 function validate_another_blog_signup() {
   313 	global $wpdb, $blogname, $blog_title, $errors, $domain, $path;
   306 	global $wpdb, $blogname, $blog_title, $errors, $domain, $path;
   314 	$current_user = wp_get_current_user();
   307 	$current_user = wp_get_current_user();
   315 	if ( !is_user_logged_in() )
   308 	if ( ! is_user_logged_in() ) {
   316 		die();
   309 		die();
       
   310 	}
   317 
   311 
   318 	$result = validate_blog_form();
   312 	$result = validate_blog_form();
   319 	extract($result);
   313 
       
   314 	// Extracted values set/overwrite globals.
       
   315 	$domain = $result['domain'];
       
   316 	$path = $result['path'];
       
   317 	$blogname = $result['blogname'];
       
   318 	$blog_title = $result['blog_title'];
       
   319 	$errors = $result['errors'];
   320 
   320 
   321 	if ( $errors->get_error_code() ) {
   321 	if ( $errors->get_error_code() ) {
   322 		signup_another_blog($blogname, $blog_title, $errors);
   322 		signup_another_blog($blogname, $blog_title, $errors);
   323 		return false;
   323 		return false;
   324 	}
   324 	}
   336 	 * @since MU
   336 	 * @since MU
   337 	 * @deprecated 3.0.0 Use the 'add_signup_meta' filter instead.
   337 	 * @deprecated 3.0.0 Use the 'add_signup_meta' filter instead.
   338 	 *
   338 	 *
   339 	 * @param array $blog_meta_defaults An array of default blog meta variables.
   339 	 * @param array $blog_meta_defaults An array of default blog meta variables.
   340 	 */
   340 	 */
   341 	$meta = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults );
   341 	$meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults );
   342 	/**
   342 	/**
   343 	 * Filter the new default site meta variables.
   343 	 * Filter the new default site meta variables.
   344 	 *
   344 	 *
   345 	 * @since 3.0.0
   345 	 * @since 3.0.0
   346 	 *
   346 	 *
   349 	 *
   349 	 *
   350 	 *     @type int $lang_id     The language ID.
   350 	 *     @type int $lang_id     The language ID.
   351 	 *     @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
   351 	 *     @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
   352 	 * }
   352 	 * }
   353 	 */
   353 	 */
   354 	$meta = apply_filters( 'add_signup_meta', $meta );
   354 	$meta = apply_filters( 'add_signup_meta', $meta_defaults );
   355 
   355 
   356 	wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
   356 	wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
   357 	confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
   357 	confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
   358 	return true;
   358 	return true;
   359 }
   359 }
   387 /**
   387 /**
   388  * Setup the new user signup process
   388  * Setup the new user signup process
   389  *
   389  *
   390  * @since MU
   390  * @since MU
   391  *
   391  *
   392  * @uses apply_filters() filter $filtered_results
       
   393  * @uses show_user_form() to display the user registration form
       
   394  * @param string $user_name The username
   392  * @param string $user_name The username
   395  * @param string $user_email The user's email
   393  * @param string $user_email The user's email
   396  * @param array $errors
   394  * @param array $errors
   397  */
   395  */
   398 function signup_user($user_name = '', $user_email = '', $errors = '') {
   396 function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
   399 	global $current_site, $active_signup;
   397 	global $active_signup;
   400 
   398 
   401 	if ( !is_wp_error($errors) )
   399 	if ( !is_wp_error($errors) )
   402 		$errors = new WP_Error();
   400 		$errors = new WP_Error();
   403 
   401 
   404 	$signup_for = isset( $_POST[ 'signup_for' ] ) ? esc_html( $_POST[ 'signup_for' ] ) : 'blog';
   402 	$signup_for = isset( $_POST[ 'signup_for' ] ) ? esc_html( $_POST[ 'signup_for' ] ) : 'blog';
   427 	$user_email = $filtered_results['user_email'];
   425 	$user_email = $filtered_results['user_email'];
   428 	$errors = $filtered_results['errors'];
   426 	$errors = $filtered_results['errors'];
   429 
   427 
   430 	?>
   428 	?>
   431 
   429 
   432 	<h2><?php printf( __( 'Get your own %s account in seconds' ), $current_site->site_name ) ?></h2>
   430 	<h2><?php printf( __( 'Get your own %s account in seconds' ), get_current_site()->site_name ) ?></h2>
   433 	<form id="setupform" method="post" action="wp-signup.php">
   431 	<form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
   434 		<input type="hidden" name="stage" value="validate-user-signup" />
   432 		<input type="hidden" name="stage" value="validate-user-signup" />
   435 		<?php
   433 		<?php
   436 		/** This action is documented in wp-signup.php */
   434 		/** This action is documented in wp-signup.php */
   437 		do_action( 'signup_hidden_fields', 'validate-user' );
   435 		do_action( 'signup_hidden_fields', 'validate-user' );
   438 		?>
   436 		?>
   460 /**
   458 /**
   461  * Validate the new user signup
   459  * Validate the new user signup
   462  *
   460  *
   463  * @since MU
   461  * @since MU
   464  *
   462  *
   465  * @uses validate_user_form() to retrieve an array of the user data
       
   466  * @uses wpmu_signup_user() to signup the new user
       
   467  * @uses confirm_user_signup() to confirm the new user signup
       
   468  * @return bool True if new user signup was validated, false if error
   463  * @return bool True if new user signup was validated, false if error
   469  */
   464  */
   470 function validate_user_signup() {
   465 function validate_user_signup() {
   471 	$result = validate_user_form();
   466 	$result = validate_user_form();
   472 	extract($result);
   467 	$user_name = $result['user_name'];
       
   468 	$user_email = $result['user_email'];
       
   469 	$errors = $result['errors'];
   473 
   470 
   474 	if ( $errors->get_error_code() ) {
   471 	if ( $errors->get_error_code() ) {
   475 		signup_user($user_name, $user_email, $errors);
   472 		signup_user($user_name, $user_email, $errors);
   476 		return false;
   473 		return false;
   477 	}
   474 	}
   510 /**
   507 /**
   511  * Setup the new site signup
   508  * Setup the new site signup
   512  *
   509  *
   513  * @since MU
   510  * @since MU
   514  *
   511  *
   515  * @uses apply_filters() to filter $filtered_results
       
   516  * @uses show_blog_form() to display the blog signup form
       
   517  * @param string $user_name The username
   512  * @param string $user_name The username
   518  * @param string $user_email The user's email address
   513  * @param string $user_email The user's email address
   519  * @param string $blogname The site name
   514  * @param string $blogname The site name
   520  * @param string $blog_title The site title
   515  * @param string $blog_title The site title
   521  * @param array $errors
   516  * @param array $errors
   575 /**
   570 /**
   576  * Validate new site signup
   571  * Validate new site signup
   577  *
   572  *
   578  * @since MU
   573  * @since MU
   579  *
   574  *
   580  * @uses wpmu_validate_user_signup() to retrieve an array of the new user data and errors
       
   581  * @uses wpmu_validate_blog_signup() to retrieve an array of the new site data and errors
       
   582  * @uses apply_filters() to make signup $meta filterable
       
   583  * @uses signup_user() to signup a new user
       
   584  * @uses signup_blog() to signup a the new user to a new site
       
   585  * @return bool True if the site signup was validated, false if error
   575  * @return bool True if the site signup was validated, false if error
   586  */
   576  */
   587 function validate_blog_signup() {
   577 function validate_blog_signup() {
   588 	// Re-validate user info.
   578 	// Re-validate user info.
   589 	$result = wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
   579 	$user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
   590 	extract($result);
   580 	$user_name = $user_result['user_name'];
   591 
   581 	$user_email = $user_result['user_email'];
   592 	if ( $errors->get_error_code() ) {
   582 	$user_errors = $user_result['errors'];
   593 		signup_user($user_name, $user_email, $errors);
   583 
       
   584 	if ( $user_errors->get_error_code() ) {
       
   585 		signup_user( $user_name, $user_email, $user_errors );
   594 		return false;
   586 		return false;
   595 	}
   587 	}
   596 
   588 
   597 	$result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']);
   589 	$result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] );
   598 	extract($result);
   590 	$domain = $result['domain'];
       
   591 	$path = $result['path'];
       
   592 	$blogname = $result['blogname'];
       
   593 	$blog_title = $result['blog_title'];
       
   594 	$errors = $result['errors'];
   599 
   595 
   600 	if ( $errors->get_error_code() ) {
   596 	if ( $errors->get_error_code() ) {
   601 		signup_blog($user_name, $user_email, $blogname, $blog_title, $errors);
   597 		signup_blog($user_name, $user_email, $blogname, $blog_title, $errors);
   602 		return false;
   598 		return false;
   603 	}
   599 	}
   604 
   600 
   605 	$public = (int) $_POST['blog_public'];
   601 	$public = (int) $_POST['blog_public'];
   606 	$meta = array ('lang_id' => 1, 'public' => $public);
   602 	$signup_meta = array ('lang_id' => 1, 'public' => $public);
   607 
   603 
   608 	/** This filter is documented in wp-signup.php */
   604 	/** This filter is documented in wp-signup.php */
   609 	$meta = apply_filters( 'add_signup_meta', $meta );
   605 	$meta = apply_filters( 'add_signup_meta', $signup_meta );
   610 
   606 
   611 	wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
   607 	wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
   612 	confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
   608 	confirm_blog_signup($domain, $path, $blog_title, $user_name, $user_email, $meta);
   613 	return true;
   609 	return true;
   614 }
   610 }