signup_user

函数
signup_user ( $user_name = '', $user_email = '', $errors = '' )
参数
  • (string) $user_name The username.
    Required:
    Default: (empty)
  • (string) $user_email The user's email.
    Required:
    Default: (empty)
  • (WP_Error|string) $errors A WP_Error object containing existing errors. Defaults to empty string.
    Required:
    Default: (empty)
定义位置
相关方法
wpmu_signup_userdo_signup_headersetup_userdatasignup_blogis_blog_user
引入
-
弃用
-

signup_user: 这个函数用于在WordPress多站点安装中创建一个新的用户。它需要两个参数–$username和$email–这是新用户的用户名和电子邮件地址。

显示访问者注册新用户帐户的表单。

function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
	global $active_signup;

	if ( ! is_wp_error( $errors ) ) {
		$errors = new WP_Error();
	}

	$signup_for = isset( $_POST['signup_for'] ) ? esc_html( $_POST['signup_for'] ) : 'blog';

	$signup_user_defaults = array(
		'user_name'  => $user_name,
		'user_email' => $user_email,
		'errors'     => $errors,
	);

	/**
	 * Filters the default user variables used on the user sign-up form.
	 *
	 * @since 3.0.0
	 *
	 * @param array $signup_user_defaults {
	 *     An array of default user variables.
	 *
	 *     @type string   $user_name  The user username.
	 *     @type string   $user_email The user email address.
	 *     @type WP_Error $errors     A WP_Error object with possible errors relevant to the sign-up user.
	 * }
	 */
	$filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
	$user_name        = $filtered_results['user_name'];
	$user_email       = $filtered_results['user_email'];
	$errors           = $filtered_results['errors'];

	?>

	<h2>
	<?php
		/* translators: %s: Name of the network. */
		printf( __( 'Get your own %s account in seconds' ), get_network()->site_name );
	?>
	</h2>
	<form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
		<input type="hidden" name="stage" value="validate-user-signup" />
		<?php
		/** This action is documented in wp-signup.php */
		do_action( 'signup_hidden_fields', 'validate-user' );
		?>
		<?php show_user_form( $user_name, $user_email, $errors ); ?>

		<?php if ( 'blog' === $active_signup ) : ?>
			<input id="signupblog" type="hidden" name="signup_for" value="blog" />
		<?php elseif ( 'user' === $active_signup ) : ?>
			<input id="signupblog" type="hidden" name="signup_for" value="user" />
		<?php else : ?>
			<fieldset class="signup-options">
				<legend><?php _e( 'Create a site or only a username:' ); ?></legend>
				<p class="wp-signup-radio-buttons">
					<span class="wp-signup-radio-button">
						<input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
						<label class="checkbox" for="signupblog"><?php _e( 'Gimme a site!' ); ?></label>
					</span>
					<span class="wp-signup-radio-button">
						<input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
						<label class="checkbox" for="signupuser"><?php _e( 'Just a username, please.' ); ?></label>
					</span>
				</p>
			</fieldset>
		<?php endif; ?>

		<p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Next' ); ?>" /></p>
	</form>
	<?php
}

常见问题

FAQs
查看更多 >